Guardrail frameworks compared¶
In one sentence¶
Guardrail frameworks are libraries and models that package common checks (injection and jailbreak detection, content safety, PII, output validation, topic control) so you don't build every check from scratch; the main open-source options are NeMo Guardrails, Guardrails AI, Llama Guard and Prompt Guard, Presidio and LLM Guard.
Why it matters in 2027¶
You'll be asked to choose and justify one. Each solves a different slice of the problem, so most production systems combine two or three, plus hosted checks from their model provider. Knowing what each is good at saves weeks of trial and error.
Explain it like I'm new¶
Home security. One company sells door locks, another sells cameras, another sells smoke detectors, and one sells a control panel that connects them all. You don't buy five control panels. You pick the panel and add the detectors you need.
How it works¶
| Tool | What it is | Best for | Notes |
|---|---|---|---|
| NeMo Guardrails (NVIDIA) | A framework for defining input, output, dialog and retrieval "rails", using config files and a small language called Colang | Orchestrating several checks; keeping a bot on approved topics and flows | The "control panel". Can call other checkers, including Llama Guard and Presidio |
| Guardrails AI | A Python library that runs "validators" on model output, with a hub of reusable validators | Structured output, format checks, reask-on-failure | Strong for "make sure output matches this schema and these rules" |
| Llama Guard 4 (Meta) | An open model that classifies prompts and responses as safe or unsafe against a list of hazard categories | Content-safety classification you can self-host | Needs a GPU to run yourself; also available from some hosted providers |
| Prompt Guard 2 (Meta) | Small classifier models that detect prompt injection and jailbreak attempts | A fast first-pass injection filter | Small enough to run on CPU |
| Presidio (Microsoft) | PII detection and anonymization using patterns plus entity models | Finding and masking personal data | Add custom recognizers for Aadhaar, PAN, UPI IDs |
| LLM Guard (Protect AI) | A collection of input and output scanners (injection, PII, secrets, toxicity and more) | A ready-made set of scanners in one library | Easy to try, then keep only the scanners you need |
| Provider safety features | Hosted moderation and safety settings (OpenAI Moderation, Gemini safety settings, Azure prompt shields) | Zero-setup baseline | Only covers that provider's models; you can't tune much |
How to choose:
- Start with what your model provider gives you and keep it on.
- Add PII handling (Presidio or your own patterns) if you touch personal data. Almost everyone does.
- Add an injection classifier (Prompt Guard or LLM Guard) if you read untrusted text, which RAG apps and agents always do.
- Add output validation (Guardrails AI, or Pydantic plus your own checks) if code consumes model output.
- Add an orchestrator (NeMo Guardrails) when you have enough rails that wiring them by hand gets messy.
- Measure false positives, false negatives and added latency on your own data before rolling out (evaluation).
Example¶
A typical layered setup for a support chatbot:
flowchart LR
I[User message] --> P[Presidio<br/>mask PII]
P --> G[Prompt Guard<br/>injection score]
G --> M[Model]
M --> L[Llama Guard<br/>content safety]
L --> V[Pydantic / Guardrails AI<br/>schema + rules]
V --> O[Reply]
Project P4 builds these layers in plain Python, so you can see exactly what each one does. Swapping in a framework later is then straightforward.
Common mistakes¶
- Installing everything. Each layer adds latency and false positives. Add one, measure, then add the next.
- Default thresholds forever. Tune them on your own traffic.
- No fallback when a guardrail service is down. Decide whether to fail open (allow) or closed (block) for each check. For safety checks, closed is usually right.
- Assuming English-only models work for Indian languages. Test with Hindi, Hinglish and the other languages your users write in.
Check yourself¶
- Which tool would you pick to mask Aadhaar numbers, and what would you need to add?
- What's the difference between Llama Guard and Prompt Guard?
- When does an orchestrator like NeMo Guardrails become worth it?
Answers
- Presidio, with a custom recognizer for the Aadhaar format (and ideally its checksum).
- Llama Guard classifies content as safe or unsafe against hazard categories. Prompt Guard detects injection and jailbreak attempts.
- When you have several rails (input, output, topic, retrieval) and wiring them together by hand becomes hard to maintain.
Go deeper¶
- NeMo Guardrails documentation - Concepts and a getting-started guide. Beginner · Docs · 30 min
- Llama Guard 4 model card by Meta - Hazard categories and prompt format. Intermediate · Docs · 15 min
- LLM Guard - Try its scanners in a notebook. Beginner · Repo · 20 min