Principle:Guardrails ai Guardrails Custom Validator Integration
| Knowledge Sources | |
|---|---|
| Domains | Validation, Integration |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
An integration principle for attaching custom-built validators to a Guard pipeline and configuring their failure behavior and validation targets.
Description
Custom Validator Integration bridges the gap between a standalone custom validator class and a working Guard pipeline. After a validator is implemented and registered, it must be instantiated with its specific parameters and on-fail action, then attached to a Guard targeting the appropriate output scope (full output, specific field, or input messages).
This step transforms a custom validator from a reusable component into an active part of a specific validation pipeline, with its failure behavior and scope configured for the use case.
Usage
After implementing and registering a custom validator, instantiate it with application-specific parameters and an on_fail action. Then attach it to a Guard using .use(), specifying the on target if needed.
Theoretical Basis
Integration follows three configuration decisions:
- Parameterization: Instantiate the validator with use-case-specific settings (thresholds, patterns, etc.)
- Failure Strategy: Choose the on_fail action: EXCEPTION (strict), FIX (auto-correct), REASK (LLM retry), FILTER (remove), REFRAIN (return None), NOOP (log only)
- Target Scope: Choose validation target: "output" (full LLM output), "messages" (input validation), or a JSON path like "$.field" (field-level)