Guardrails are evaluators that run in real-time and act on the results - blocking, modifying, or rejecting responses that violate your safety or policy rules. Unlike monitors which only measure and alert, guardrails actively prevent harmful content from reaching users.Documentation Index
Fetch the complete documentation index at: https://langwatch.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Guardrails vs Monitors
| Guardrails | Monitors |
|---|---|
| Block harmful content | Measure quality metrics |
| Run synchronously during request | Run asynchronously after response |
| Return errors or safe responses | Feed dashboards and alerts |
| Add latency to requests | No impact on response time |
| For enforcement | For observability |
Use guardrails when you need to prevent something from happening. Use monitors when you need to observe what’s happening.
Common Guardrail Use Cases
| Use Case | Evaluator | Action |
|---|---|---|
| Block jailbreak attempts | Azure Jailbreak Detection | Reject input |
| Prevent PII exposure | Presidio PII Detection | Block or redact response |
| Enforce content policy | OpenAI Moderation | Return safe response |
| Block competitor mentions | Competitor Blocklist | Modify or reject |
| Ensure valid output format | Valid Format Evaluator | Retry or reject |
How Guardrails Work
- Input guardrails - Check user input before calling your LLM
- Output guardrails - Check LLM response before sending to user
Getting Started
Code Integration
Available Evaluators
Quick Example
- Python
- TypeScript
Best Practices
1. Layer your guardrails
Use multiple guardrails for defense in depth:2. Provide helpful error messages
Don’t just block - guide users toward acceptable behavior:3. Log guardrail triggers
Track when guardrails fire for monitoring and improvement:4. Consider latency
Guardrails add latency. For time-sensitive applications:- Use fast evaluators (regex, blocklists) for input checks
- Save heavier evaluators (LLM-based) for output checks
- Run multiple guardrails in parallel when possible
Recommended Evaluators for Guardrails
| Evaluator | Best For | Latency |
|---|---|---|
| Azure Jailbreak Detection | Blocking prompt injection | Fast |
| Azure Prompt Shield | Blocking prompt attacks | Fast |
| Presidio PII Detection | Blocking PII exposure | Fast |
| OpenAI Moderation | Content policy enforcement | Fast |
| Competitor Blocklist | Blocking competitor mentions | Very Fast |
| Valid Format | Ensuring structured output | Very Fast |
| LLM-as-Judge Boolean | Custom policy checks | Slower |