> ## Documentation Index
> Fetch the complete documentation index at: https://docs.royaltyport.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Validator

> Validate data using AI-powered rules in your automation workflows

## Overview

The Validator step acts as a quality gate in your workflow. It takes the output from previous steps and checks it against validation rules you describe in natural language. The AI evaluates each rule and returns a boolean `valid` result plus an array of specific error messages for any rules that failed.

This is useful when you need to:

* Verify required fields are present before writing to a database
* Check that API response data meets expected formats or ranges
* Enforce business rules (e.g. "royalty rate must be between 0 and 1")
* Catch bad data early before it flows to downstream steps

## How It Works

At runtime, the Validator receives the full execution context as input. Your prompt defines the rules to check. The AI returns a structured result with `valid` (true/false) and `errors` (an array of human-readable error strings). When `valid` is `false`, you can use [branches](/automations/steps/overview#branches--conditions) to route the workflow to an error-handling path.

<AccordionGroup>
  <Accordion title="Example: validate contract data">
    **Prompt:**

    ```
    Validate the contract data:
    - "title" must be a non-empty string
    - "effective_date" must be a valid date in YYYY-MM-DD format
    - "royalty_rate" must be a number between 0 and 1
    - "parties" must be an array with at least 2 entries
    ```

    **Output when valid:**

    ```json theme={null}
    {
      "valid": true,
      "errors": []
    }
    ```

    **Output when invalid:**

    ```json theme={null}
    {
      "valid": false,
      "errors": [
        "royalty_rate is 1.5, which exceeds the maximum of 1",
        "parties has only 1 entry, minimum is 2"
      ]
    }
    ```
  </Accordion>
</AccordionGroup>

## Configuration

| Field      | Description                                                                                                                                                                                 |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Prompt** | Natural language validation rules to check against the input data. Use [template variables](/automations/steps/overview#template-variables) to reference specific data from previous steps. |

### Writing Good Prompts

* **List rules explicitly** — each rule on its own line makes it easier for the AI to evaluate and report individually
* **Include expected types and ranges** — "must be a number between 0 and 100" is better than "must be reasonable"
* **Be specific about what counts as failure** — e.g. "empty strings and null values should fail the non-empty check"

### Using Libraries

The prompt editor has built-in [library](/automations/libraries) integration. Click **Library** above the editor to load a saved prompt, or click **Save** to store the current prompt as a reusable library item. This is useful when the same validation rules apply across multiple automations.

## Output

| Field           | Type    | Description                                                               |
| --------------- | ------- | ------------------------------------------------------------------------- |
| `valid`         | boolean | Whether all validation rules passed                                       |
| `errors`        | array   | List of human-readable error messages for failed rules (empty when valid) |
| `error`         | boolean | Whether a system error occurred                                           |
| `error_message` | string  | Error description if the step itself failed                               |

<Tip>
  Combine with branches to create conditional paths: add a branch on `output.valid` equals `false` to route to error handling, and let the default connector continue the happy path.
</Tip>
