Cette page est affichée en anglais. Une traduction française est en cours.
WorkflowsApr 8, 2026·2 min de lecture

Guardrails AI — Validate LLM Outputs in Production

Add validation and guardrails to any LLM output. Guardrails AI checks for hallucination, toxicity, PII leakage, and format compliance with 50+ built-in validators.

What is Guardrails AI?

Guardrails AI is a framework for adding validation, safety checks, and structural constraints to LLM outputs. It provides 50+ pre-built validators from the Guardrails Hub — covering hallucination detection, PII filtering, toxicity checking, format validation, and more. Wrap any LLM call with a Guard to automatically validate and fix outputs before they reach users.

Answer-Ready: Guardrails AI validates LLM outputs with 50+ validators from Guardrails Hub. Checks hallucination, PII, toxicity, and format compliance. Auto-retries on validation failure. Works with OpenAI, Claude, any LLM. Production-ready with Guardrails Server. 4k+ GitHub stars.

Best for: AI teams deploying LLMs in production needing output safety. Works with: OpenAI, Anthropic Claude, LangChain, any LLM. Setup time: Under 5 minutes.

Core Features

1. Guardrails Hub (50+ Validators)

Category Validators
Safety ToxicLanguage, NSFWText, ProfanityFree
Privacy DetectPII, AnonymizePII
Accuracy FactualConsistency, NoHallucination
Format ValidJSON, ValidURL, RegexMatch
Quality ReadingLevel, Conciseness, Relevancy
Code ValidSQL, ValidPython, BugFreePython

2. LLM Integration

from guardrails import Guard
from guardrails.hub import ToxicLanguage, DetectPII

guard = Guard().use_many(
    ToxicLanguage(on_fail="filter"),
    DetectPII(on_fail="fix"),
)

# Wrap any LLM call
result = guard(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Summarize this customer complaint"}],
)
print(result.validated_output)  # PII removed, toxicity filtered

3. Auto-Retry on Failure

guard = Guard().use(ValidJSON(on_fail="reask"))

# If LLM returns invalid JSON, automatically retries with corrective prompt
result = guard(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Return user data as JSON"}],
    max_reasks=3,
)

4. Structured Output

from pydantic import BaseModel

class UserProfile(BaseModel):
    name: str
    age: int
    email: str

guard = Guard.for_pydantic(output_class=UserProfile)
result = guard(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Extract user info from: John, 30, john@example.com"}],
)
print(result.validated_output)  # UserProfile(name="John", age=30, ...)

5. Guardrails Server

# Deploy as API server for production
guardrails start --config guard_config.py
# POST /guards/{guard_name}/validate

FAQ

Q: Does it work with Claude? A: Yes, pass model="anthropic/claude-sonnet-4-20250514" to the guard call.

Q: What happens when validation fails? A: Configurable per validator — filter (remove), fix (correct), reask (retry with LLM), or raise (throw error).

Q: Can I write custom validators? A: Yes, extend the Validator base class. Custom validators can use LLMs, APIs, or rule-based logic.

🙏

Source et remerciements

Created by Guardrails AI. Licensed under Apache 2.0.

guardrails-ai/guardrails — 4k+ stars

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.