Skip to main content

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

ParameterTypeRequiredDescription
rulesList<RuleItem>YesList of validation rules to evaluate

Rule Item Properties

PropertyTypeRequiredDescription
rulestringNoRule type. Currently only "required" is supported
valueobjectNoThe value to validate. Required when rule is "required". Typically a template expression (e.g., {{ fieldName }})
conditionsstringNoAn NCalc expression evaluated against task variables. Used when validating with custom logic. Variables are referenced with bracket syntax (e.g., [amount])
messagestringNoCustom error message returned when validation fails. If omitted, a default message is generated from the condition expression

Task Properties

PropertyTypeDefaultDescription
continueOnErrorboolfalseWhen 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.

OutputTypeDescription
errorsList<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 ValidationException is thrown with all error messages
  • The exception includes metadata: WorkflowId, ValidationErrorCount, and FirstErrorMessage
  • Workflow execution stops unless caught by an onWorkflowExecuted event handler