Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Guardrails ai Guardrails Validator Registration

From Leeroopedia
Revision as of 17:19, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Guardrails_ai_Guardrails_Validator_Registration.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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:

  1. Name Validation: Verify the name is unique and data types are valid
  2. Registry Entry: Store class reference in validators_registry[name]
  3. Type Mapping: Append validator name to types_to_validators[data_type] for each supported type
  4. Alias Setting: Set cls.rail_alias = name for runtime identification

For function-based validators, a Validator subclass is dynamically created via validator_factory.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment