Validator Nodes

Overview

Validator nodes are essential components within Dynamiq's platform that perform data validation within your workflows. These nodes act as quality control checkpoints, ensuring that data meets specific criteria before proceeding through the workflow.

Validator nodes in Dynamiq

Key Features

  • Flexible validation rules

  • Configurable error handling behavior

  • Support for multiple data formats

  • Built-in error messaging

Available Validators

1. Valid Python (ValidPython)

Available validators on Dynamiq

Validates that the input content follows the correct Python syntax.

Example Usage:

{
    "content": "def hello_world():\n    print('Hello, World!')"
}

2. Valid JSON (ValidJSON)

Ensures input content is properly formatted JSON. Handles both string and dictionary inputs.

Example Usage:

{
    "content": {"name": "John", "age": 30}
}

3. Valid Choices (ValidChoices)

Verifies that the input content matches one of the predefined acceptable values.

Example Configuration:

{
    "choices": ["option1", "option2", "option3"],
    "content": "option1"
}

4. Regex Match (RegexMatch)

Validates the input content against a specified regular expression pattern.

Match Types:

  • fullmatch: Entire string must match the pattern

  • search: Pattern can match anywhere in the string

Example Configuration:

{
    "regex": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}$",
    "match_type": "fullmatch",
    "content": "[email protected]"
}

Configuration Options

General Settings

Each validator node shares these common configuration options:

Setting
Description
Options

Name

Node identifier in the workflow

Text input

Behavior

Action on validation failure

RAISE, RETURN

Validator-Specific Settings

Valid Choices

  • Choices: List of acceptable values

  • Strip whitespace: Automatically applied to string inputs

Regex Match

  • Regex: Regular expression pattern

  • Match_type: FULL_MATCH or SEARCH

Response Format

When behavior is set to RETURN, validators output:

{
    "valid": bool,  # Validation result
    "content": Any  # Original input content
}

When behavior is set to RAISE, validators:

  • Return the input content if validation passes

  • Raise a ValueError with detailed error message if validation fails

Best Practices

  1. Error Handling

    • Use RAISE behavior for critical validation points

    • Use RETURN behavior when you need to handle invalid data gracefully

  2. Input Sanitization

    • Consider using RegexMatch for input sanitization

    • Valid Choices for enforcing controlled vocabularies

  3. Performance

    • Place validators early in workflows to fail fast

    • Use appropriate match types in RegexMatch to optimize performance

Common Use Cases

  1. Form Validation

{
    "type": "RegexMatch",
    "regex": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}$",
    "behavior": "RAISE"
}
  1. Configuration Validation

{
    "type": "ValidJSON",
    "behavior": "RETURN"
}
  1. Code Quality Checks

{
    "type": "ValidPython",
    "behavior": "RAISE"
}

Troubleshooting

Common validation errors and solutions:

Error
Possible Cause
Solution

"Value is not valid JSON"

Malformed JSON string

Check JSON syntax and structure

"Value is not in valid choices"

Input not in choices list

Verify input against allowed values

"Value does not match pattern"

Regex pattern mismatch

Test pattern with regex debugger

"Value is not valid python code"

Python syntax error

Check code formatting

Last updated