Validator Node
AI-generatedOverview
The Validator Node validates input data against user-defined criteria. It is useful in workflows where you need to ensure that incoming data meets specific validation rules before further processing. For example, it can check if a string is a valid email, if a number falls within a range, or if a required field is present.
Common scenarios include:
- Validating form inputs before saving to a database.
- Ensuring API response data conforms to expected formats.
- Filtering out invalid data early in a workflow.
The node supports two modes:
- Output Validation Results: Outputs each item with validation results and any errors.
- Output Items: Outputs only items that pass validation; throws an error on the first invalid item.
Properties
| Name | Meaning |
|---|---|
| Node Mode | Determines output behavior: - Output Validation Results: Outputs validation status and errors for each item. - Output Items: Outputs only valid items; errors on validation failure. |
| Inputs | Collection of input fields to validate. Each input field includes: - Validation Name: Identifier for the validation. - Validation Type: Type of validation ( boolean, date, enum, number, string).- Required: Whether the field must be present. - String Data: String value to validate (for string and enum).- String Format: Format for string validation ( email, none, pattern, url, uuid).- Number Data: Number value to validate. - Number Validation Type: Number validation mode ( none, min, max, range).- Min Value: Minimum number value (for min or range).- Max Value: Maximum number value (for max or range).- Boolean Data: Boolean value to validate. - Date Data: Date string to validate. - Enum Values: Comma-separated list of valid enum values. - Pattern: Regex pattern for string validation when using pattern format. |
Output
The node outputs an array of items, each containing:
json.isValid: A boolean indicating if the item passed validation.json.errors: An array of error objects if validation failed; otherwise undefined. Each error object contains:field: The name of the validation field that failed.message: Description of the validation error.
If the node is set to "Output Items" mode, only valid items are output. If any item fails validation, the node throws an error and stops execution.
The node does not output binary data.
Dependencies
- No external services or API keys are required.
- The node relies on an internal validation utility imported from
./validateInput. - No special environment variables or n8n configurations are needed.
Troubleshooting
Common issues:
- Validation errors due to incorrect input data types or missing required fields.
- Regex patterns that do not compile or match as expected.
- Misconfiguration of number validation ranges (e.g., min value greater than max value).
Error messages:
- When in "Output Items" mode, if an item fails validation, the node throws an error with a message listing all validation failures for that item, e.g.,
Item failed validation. <field>: <message> | <field>: <message>. - To resolve, review the validation criteria and input data for correctness.
- When in "Output Items" mode, if an item fails validation, the node throws an error with a message listing all validation failures for that item, e.g.,