Guardrails
Enhance AI applications with robust validation and error correction.. [Contact for Pricing]
Last verified:
What is Guardrails?
Guardrails AI is a Python framework for building, governing, and scaling production GenAI applications across any LLM and deployment environment. It serves as an AI reliability platform that helps teams manage unreliable GenAI behavior by enforcing input and output guards that detect, quantify, and mitigate specific types of risks like hallucinations, policy violations, PII leakage, toxic language, and formatting errors.
The platform offers two core functions: running Input/Output Guards that intercept LLM inputs and outputs to validate against configured validators, and generating structured data from LLMs using Pydantic models or RAIL (Markup) specifications. Guardrails Hub provides the largest and fastest-growing collection of 70+ community-driven, open-source validators covering risk categories including etiquette, brand risk, factuality, formatting, jailbreaking, code exploits, and data leakage. Key validators include Detect PII, Profanity Free, Valid JSON, Valid SQL, Toxic Language, Bias Check, Factuality validators like Wiki Provenance, and formatting validators like Regex Match and Valid Length.
Guardrails AI is designed for AI engineers, ML teams, and enterprises building production GenAI applications including chatbots, customer support systems, RAG applications, code generation tools, Text2SQL systems, and summarization pipelines. The framework supports automatic retries with exponential backoff for common LLM errors, maintains call history through the Guard object, and allows re-asks to LLMs when validation fails. Teams like MasterClass use Guardrails (specifically Snowglobe) for synthetic data generation and realistic user persona simulation for fine-tuning and prompt optimization.
Guardrails pricing
Pricing model: Freemium
Guardrails AI is open-source and free to use. The core guardrails-ai package is installed via pip (pip install guardrails-ai) at no cost. Guardrails Hub with 70+ validators is free and community-driven. The CLI tool (guardrails configure, guardrails hub install) is free. No paid tier or enterprise pricing is advertised on the website. Users only pay for their own LLM API costs when calling LLMs through Guardrails.
Guardrails pros
- Open-source framework with large community-driven validator collection
- 70+ pre-built validators covering diverse risk categories
- Supports structured data generation with Pydantic models
- RAIL markup language for custom validation specifications
- Works across any LLM including GPT-3.5, GPT-4, and open-source models
- Input and Output Guards intercept both prompts and responses
- Automatic retries with exponential backoff for LLM errors
- Guard object tracks call history and validation results
- Supports re-asks to LLM when validation fails
- Hub CLI for easy validator installation and management
- Validators for PII detection using Microsoft Presidio and GLiNER
- SQL validation with optional schema validation via SQLAlchemy
- Code validators for Valid Python, Valid SQL, Valid JSON, Valid HTML
- Factuality validators including Wiki Provenance and LLM Judge evaluators
- Post-processor mode with Guard.parse for custom LLM calls
- Function calling support for LLMs with structured output capability
- Prompt optimization for LLMs without function calling support
Guardrails cons
- Python-only framework limits non-Python language support
- Requires learning RAIL markup syntax for custom validators
- Some validators require external API keys (Google Maps, Bespoke MiniCheck)
- LLM-based validators add latency and cost to validation
- No built-in GUI dashboard for monitoring guardrails
- Maximum 60-second backoff may be too long for some use cases
- Mobile interface not available for Hub API keys management
- Custom validator development requires Python programming knowledge
Frequently asked questions about Guardrails
What is Guardrails AI?
Guardrails is a Python framework that helps build reliable AI applications by performing two key functions: running Input/Output Guards that detect, quantify and mitigate specific types of risks in LLM inputs and outputs, and generating structured data from LLMs using Pydantic models or RAIL markup specifications.
What is Guardrails Hub?
Guardrails Hub is a collection of 70+ pre-built validators that measure specific types of risks. Multiple validators can be combined into Input and Output Guards that intercept LLM inputs and outputs. Validators cover categories like etiquette, brand risk, factuality, formatting, jailbreaking, code exploits, and data leakage.
What is a Guard object?
The Guard object is the main interface for Guardrails. It wraps LLM calls, orchestrates validation, and keeps track of call history. It can be used without configuration for string-based LLM apps or accepts a Pydantic object for structured data use cases. The Guard returns a GuardResponse object containing raw LLM output, validated output, and validation success status.
How do I generate structured data with Guardrails?
There are two ways: using Pydantic models by creating a BaseModel with desired fields/types, then creating a Guard with Guard.for_pydantic(Person), and calling the LLM with the guard object. Alternatively, use RAIL markup by creating a RAIL spec with desired fields, then creating a Guard with Guard.for_rail_string() and calling the LLM.
What validators are available for PII detection?
Guardrails offers Detect PII validator using Microsoft Presidio, and Guardrails PII validator that uses a combination of Presidio and GLiNER for state-of-the-art PII detection and anonymization. These detect personally identifiable information in LLM-generated text and support various entity types.
Can Guardrails work as a post-processor?
Yes, you can use Guard.parse to apply your RAIL specification to LLM output as a post-process after calling the LLM yourself. You can also allow Guardrails to make re-asks by specifying the num_reasks argument, or keep it purely as a post-processor by setting num_reasks to zero.
What LLMs does Guardrails support?
Guardrails works across any LLM including OpenAI models (GPT-3.5-turbo, GPT-3.5-turbo-instruct, GPT-4) and other LLMs of your choice. For LLMs supporting function calling, it uses function call syntax for structured data. For LLMs without function calling, it adds schema to the prompt for optimization.
How does error handling work in Guardrails?
Guardrails performs automatic retries with exponential backoff for errors including APIConnectionError, APIError, TryAgain, Timeout, RateLimitError, ServiceUnavailableError, and incorrect structure from LLM. Max wait time between requests is 60 seconds. Other errors raise exceptions with troubleshooting help.
What use cases does Guardrails support?
Guardrails supports chatbots, customer support, structured data generation, RAG applications, summarization, code generation, and Text2SQL. The Hub can be filtered by these use cases to find relevant validators for your specific application type.
How do I install and start using Guardrails?
Install via pip: pip install guardrails-ai. Then configure the Hub CLI with guardrails configure. Install validators with guardrails hub install hub://guardrails/validator_name. Import Guard and validators in Python, create a Guard with guard = Guard().use(Validator()), and call guard.parse() or guard() with your LLM.