Principle:Guardrails ai Guardrails Validator Registration
| Knowledge Sources | |
|---|---|
| Domains | Plugin_Architecture, Validation |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A plugin registration principle that associates validator implementations with unique identifiers and compatible data types in a global registry.
Description
Validator Registration is the mechanism by which custom validators are made discoverable and usable by the Guardrails framework. The @register_validator decorator takes a unique name (typically namespaced as organization/validator_name) and one or more data types the validator can handle (string, integer, float, list, object, or all). It registers the validator class (or function) in a global validators_registry dict, making it available for instantiation by name.
This follows the Service Locator pattern, enabling validators to be loaded dynamically by name from Hub packages or user code without requiring explicit imports at framework initialization.
Usage
Apply this decorator to every custom validator class or function before using it with a Guard. The name must be globally unique and follow the namespace convention (e.g., my_org/my_validator).
Theoretical Basis
The registration process:
- Name Validation: Verify the name is unique and data types are valid
- Registry Entry: Store class reference in validators_registry[name]
- Type Mapping: Append validator name to types_to_validators[data_type] for each supported type
- Alias Setting: Set cls.rail_alias = name for runtime identification
For function-based validators, a Validator subclass is dynamically created via validator_factory.