Validation Task
The validation task validates input data against business rules. It supports required-field checks and custom condition expressions, and can either throw an exception or return errors for downstream handling.
YAML Structure
task: "Validation/Validate@1"
name: validate
continueOnError: false
inputs:
rules:
- rule: "required"
value: "{{ orderStatusId }}"
message: "Order status ID is required."
- conditions: "[amount] > 0"
message: "Amount must be greater than 0."
Attribute Description
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
rules | List<RuleItem> | Yes | List of validation rules to evaluate |
Rule Item Properties
| Property | Type | Required | Description |
|---|---|---|---|
rule | string | No | Rule type. Currently only "required" is supported |
value | object | No | The value to validate. Required when rule is "required". Typically a template expression (e.g., {{ fieldName }}) |
conditions | string | No | An NCalc expression evaluated against task variables. Used when validating with custom logic. Variables are referenced with bracket syntax (e.g., [amount]) |
message | string | No | Custom error message returned when validation fails. If omitted, a default message is generated from the condition expression |
Task Properties
| Property | Type | Default | Description |
|---|---|---|---|
continueOnError | bool | false | When false, throws a ValidationException that stops the workflow. When true, errors are returned in the output without throwing |
Output
The task always returns an errors list. When continueOnError is true, capture errors with an output mapping.
| Output | Type | Description |
|---|---|---|
errors | List<string> | List of validation error messages. Empty if all rules pass |
Rules
required
Validates that a value is not null and not an empty string.
- rule: "required"
value: "{{ orderId }}"
message: "Order ID is required"
Condition Expression
Evaluates an NCalc expression against the current task variables. The rule fails when the expression evaluates to false. No rule property is needed — providing conditions is sufficient.
- conditions: "[orderId] > 0"
message: "Order ID must be greater than 0"
Examples
Basic Validation
task: "Validation/Validate@1"
name: validate
inputs:
rules:
- rule: "required"
value: "{{ orderId }}"
message: "Order ID is required"
- conditions: "[orderId] > 0"
message: "Order ID must be greater than 0"
If any rule fails and continueOnError is not set (defaults to false), the workflow throws a ValidationException and stops execution.
Handling Errors Without Stopping the Workflow
Use continueOnError: true to collect errors and process them downstream instead of throwing.
task: "Validation/Validate@1"
name: validate
continueOnError: true
inputs:
rules:
- rule: "required"
value: "{{ orderId }}"
message: "Order ID is required"
- conditions: "[orderId] > 0"
message: "Order ID must be greater than 0"
outputs:
- name: "errors"
The errors output contains a list of failure messages. If all rules pass, the list is empty.
Capturing Errors at the Workflow Level
Map the validation errors to a workflow output so callers can inspect them:
outputs:
- name: "errors"
mapping: "activity.validate.errors"
activities:
- name: "activity"
steps:
- task: "Validation/Validate@1"
name: validate
continueOnError: true
inputs:
rules:
- rule: "required"
value: "{{ orderId }}"
message: "Order ID is required"
- conditions: "[orderId] > 0"
message: "Order ID must be greater than 0"
outputs:
- name: "errors"
Error Handling
When continueOnError is false (default) and validation fails:
- A
ValidationExceptionis thrown with all error messages - The exception includes metadata:
WorkflowId,ValidationErrorCount, andFirstErrorMessage - Workflow execution stops unless caught by an
onWorkflowExecutedevent handler
Related Topics
- Workflow Expressions — Expression syntax for condition rules
- Utilities Tasks — ValidateHMAC and ValidateReCaptcha tasks for security validation