Guardrails is a Python SDK that wraps calls to large language models with configurable validation pipelines, corrective actions, and structured output generation. It provides a unified API layer that connects to over 100 language models, applying consistent validation, streaming, and error-handling across providers. The framework validates and corrects model responses against safety and quality rules, detecting and mitigating risks in both inputs and outputs using pre-built and custom validators.
The project distinguishes itself through a validator-pipeline architecture that sequentially applies reusable validation rules and can automatically retry prompts or fix outputs when checks fail. It supports real-time streaming validation that applies guardrails incrementally as tokens arrive, and generates validated JSON or structured data from free-form model responses using user-defined schemas and function calling. Guardrails also offers an OpenAI-compatible server and a Flask-based REST API server for remote validation, along with LangChain integration that converts guardrail validators into runnable objects for chains and agents.
The framework includes an observability layer that logs every model interaction, validator result, and performance metric for export to monitoring and debugging platforms. It supports custom model adapters for unsupported LLM APIs, user-defined validation rules, and declarative configuration files that specify validators and violation responses. The system handles concurrent LLM interactions with async support and parallelization for efficient real-time processing.