Guardrails AI
Validate, fix, and filter LLM outputs — define structured schemas and safety rules, then automatically retry when outputs fail validation.
Guardrails AI
Guardrails AI is an open-source framework for adding structured validation and safety checks to LLM outputs. Define a Guard with validators — JSON schema enforcement, PII detection, toxicity filtering, length limits, regex matching, and more — and Guardrails automatically re-prompts when outputs fail.
Key features
- Rail spec — declare the expected output structure and validators in YAML or Python
- 100+ validators — built-in checks for PII, toxicity, bias, valid JSON, SQL safety, and more
- Auto-fix and retry — on failure, Guardrails re-prompts with error feedback or programmatically fixes outputs
- Streaming support — validate streaming chunks as they arrive
- Hub — community-contributed validators for domain-specific rules
- Provider-agnostic — works with OpenAI, Anthropic, Cohere, and any LangChain-compatible model
Quick start
npx ai-supply add guardrails-ai-output-validation
# Or install directly
pip install guardrails-ai
guardrails hub install hub://guardrails/valid_json
from guardrails import Guard
from guardrails.hub import ValidJson
guard = Guard().use(ValidJson, on_fail="reask")
result = guard(
lambda: '{"name": "Alice", "age": 30}', # Replace with your LLM call
prompt="Return a JSON object with name and age."
)
print(result.validated_output) # {"name": "Alice", "age": 30}
Curated mirror of the open-source Guardrails AI project (Apache-2.0). Install upstream from the repository.
Compromise signals — malicious or tampered code (leaked secrets, backdoors, a dropped executable) — reduce the score, and known dependency CVEs carry a bounded penalty (they warrant review but never QUARANTINE — update the dependency to clear). Other dangerous-by-capability traits are risk surface, expected for some capabilities. Every finding is mapped to its OWASP control below.
Findings mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Machine Learning Security Top 10. Expand any flagged control for the exact findings — compromise reduces the score; expected/risk-surface do not, except a known CVE, which carries a small bounded penalty (high/critical → Review).
The same gate an agent runs before installing (POST /api/v1/trust/guardrails-ai-output-validation/check). Click a policy:
Consume Guardrails AI programmatically. Authenticate with an API key or session — see Authorize an agent.
# Agents: CHECK BEFORE YOU INSTALL (no auth) — score, grade, level, capability manifest
curl https://ai-supply.store/api/v1/trust/guardrails-ai-output-validation
# Gate against your org policy (returns { pass, violations })
curl -X POST https://ai-supply.store/api/v1/trust/guardrails-ai-output-validation/check \
-H "Content-Type: application/json" \
-d '{"minGrade":"B","denyPermissions":["shell"],"denyUnknownEgress":true}'
# CLI
npx ai-supply add guardrails-ai-output-validation
# REST (install → download)
curl -X POST https://ai-supply.store/api/v1/listings/guardrails-ai-output-validation/install \
-H "Authorization: Bearer $AIM_KEY"
# MCP tool
install_listing({ "slug": "guardrails-ai-output-validation" })OpenAPI spec →Curated mirror — latest upstream source. See the repository for tagged releases.