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 RailSpecification

From Leeroopedia

Template:Principle

Overview

The RAIL Specification principle covers the Reliable AI Markup Language (RAIL), an XML-based format for declaratively defining validator schemas and configurations. RAIL provides a structured way to specify the expected output format of an LLM call alongside the validators that should be applied to each field. By embedding both schema structure and validation rules in a single document, RAIL enables users to express complex validation requirements without writing procedural code.

A RAIL document defines output elements with types, descriptions, and associated validators. Each element can carry attributes that specify which validators to run, what parameters to pass, and what action to take on failure (e.g., reask, filter, fix). This declarative approach separates the what (validation requirements) from the how (validation execution), following the same philosophy as HTML for document structure or SQL for data queries.

The framework converts between RAIL XML and JSON Schema representations bidirectionally. A RAIL document can be parsed into the internal JSON Schema representation used by the validation engine, and conversely, a JSON Schema with validator annotations can be serialized back to RAIL XML. This bidirectional conversion ensures that RAIL remains interoperable with the broader JSON Schema ecosystem while providing its own ergonomic authoring experience.

Theoretical Basis

The RAIL Specification is grounded in the Domain-Specific Language (DSL) pattern. RAIL is a purpose-built language for expressing validation schemas, tailored to the specific needs of LLM output validation. Like other XML-based DSLs (such as XSLT for transformations or Ant for build scripts), RAIL leverages the well-understood XML syntax and tooling while adding domain-specific semantics through its element and attribute vocabulary.

The bidirectional conversion between RAIL and JSON Schema follows the Two-Way Mapping pattern, where each format can serve as the source of truth and be translated to the other without loss of essential information. The RAIL parser acts as a Deserializer that reads XML and produces the internal schema model, while the RAIL serializer acts as a Serializer that writes the internal model back to XML. This symmetry is important for round-trip editing workflows where users may switch between RAIL and JSON Schema representations during development.

Related Pages

Implementations

Workflows

(To be connected)

Page Connections

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