Blog / Guardrails and defenses
LLM Guardrails: What They Are and How to Choose Them
FrostWolf Research · · 11 min read
LLM guardrails are checks that run outside the model and inspect what goes into it and what comes out of it, then allow, modify or block the exchange. They catch prompt injection, jailbreaks, leaked personal data, unsafe content, off-topic requests and dangerous tool calls that the model's own training lets through. To choose them, start from the risks your application actually has, place a check at each point where untrusted data enters or model output takes effect, and measure every check for catch rate, false positives and latency before it goes to production.
This guide covers what counts as a guardrail, the main types, where each one sits in a request, the open and managed options available as of October 2026, what guardrails cannot do, and a selection process you can run in a week.
What are LLM guardrails?
A guardrail is a policy check that you control, applied at runtime, to the inputs or outputs of a language model. It is separate from the model itself. The model's safety training (often called alignment) is a property of its weights; a guardrail is a component in your application that you can configure, log, tune and replace.
The term covers a wide range of mechanisms. A regular expression that blocks credit card numbers is a guardrail. So is an 8-billion-parameter classifier that labels a response as unsafe, a JSON schema that rejects malformed tool arguments, and a rule that an agent may not send email to a domain outside the company. What they share is position: they sit between the model and the rest of the world.
The NeMo Guardrails paper from NVIDIA puts the distinction well. Alignment is embedded in the model at training time. Programmable rails are "user-defined, independent of the underlying LLM, and interpretable." That independence is the point. You can change a guardrail on Tuesday without retraining anything, and you can audit why it fired.
Why do LLM applications need guardrails?
Language models do not separate instructions from data. Everything in the context window is text, and a well-placed sentence in a retrieved document can carry the same weight as your system prompt. That is the root of prompt injection, which the OWASP Top 10 for LLM Applications ranks first.
Training does not close this gap. Model providers keep improving resistance, but research keeps finding ways around it. In October 2025, a team from OpenAI, Anthropic and Google DeepMind published adaptive attacks that bypassed 12 recent defenses with attack success rates above 90 percent for most, even though most of those defenses had originally reported near-zero attack success.
Guardrails exist because the model is not a reliable security boundary. OWASP's guidance on system prompt leakage says it plainly: security controls must be "enforced independently from the LLM." A guardrail is one way to do that. Least privilege, deterministic authorization and human review are others, and you need them too.
What types of guardrails are there?
Guardrails fall into a handful of families. Most production systems use several.
| Type | What it checks | Typical mechanism | Example tools |
|---|---|---|---|
| Prompt attack detection | Injection and jailbreak attempts in user input and retrieved content | Small fine-tuned classifier | Llama Prompt Guard 2, Azure Prompt Shields |
| Content safety | Harmful categories such as violence, hate, self-harm | LLM-based safety classifier | Llama Guard 4, ShieldGemma, Qwen3Guard |
| Sensitive data | PII, secrets, credentials going in or coming out | Entity recognition plus rules | Presidio, cloud DLP services |
| Topic and scope | Requests outside the application's purpose | Classifier or dialog rules | NeMo Guardrails dialog rails |
| Grounding | Answers not supported by retrieved sources | Judge model | Granite Guardian, Bedrock contextual grounding |
| Structure | Output format, schema, types | Parser and validator | Guardrails AI, JSON Schema |
| Tool-call validation | Which tools the model calls and with what arguments | Allowlist, schema, policy engine | LlamaFirewall, custom policy |
| Code safety | Insecure code the model writes | Static analysis | CodeShield |
Prompt attack detection
These guardrails look for text that tries to override the developer's instructions. They are usually small encoder models chosen for speed. Meta's Llama Prompt Guard 2 comes in 86M and 22M parameter versions with a 512-token window and a binary benign-or-malicious label. Microsoft's Prompt Shields separate "user prompt attacks" from "document attacks", which is a useful split: an attack in a user's message and an attack hidden in a retrieved web page are different problems. See how prompt injection detection works and where it fails for the mechanics.
Content safety classifiers
These label prompts and responses against a harm taxonomy. Most open ones are fine-tuned LLMs that read a conversation and emit a label. Llama Guard 4 is a 12-billion-parameter multimodal classifier trained on 14 categories based on the MLCommons hazard taxonomy. They answer a different question from prompt attack detectors. A polite, harmless-looking instruction to forward a user's inbox to an attacker is a prompt injection with no harmful content at all, and a content classifier will usually call it safe. The Llama Guard deep dive covers how one of these works.
Sensitive data guardrails
These find personal data, secrets and regulated identifiers, then redact, mask or replace them before text reaches the model or leaves the system. The design questions are which entity types matter, what to put in their place, and whether you need the original value back in the response. PII redaction for LLMs compares the strategies.
Grounding and hallucination checks
In retrieval-augmented generation, a judge model compares the answer to the retrieved passages and flags claims the sources do not support. IBM's Granite Guardian was built with RAG risks such as context relevance, groundedness and answer relevance in mind, and Amazon Bedrock offers a contextual grounding check for the same purpose.
Structural and tool-call guardrails
Not every guardrail is a model. Validating that a tool call names a tool the agent is allowed to use, with arguments that match its schema, is deterministic and cheap, and it stops a class of attacks that classifiers miss. Validating LLM tool calls goes deeper. Meta's LlamaFirewall combines a prompt attack classifier, a chain-of-thought auditor that checks whether an agent's actions still match the user's goal, and CodeShield static analysis for generated code.
Where do guardrails sit in a request?
Placement matters as much as choice. A request in a modern LLM application passes through several points where a check can run:
- User input, before the model sees it.
- Retrieved and tool-returned content, before it is added to the context. This is where indirect prompt injection enters.
- Model output, before it is shown to the user or parsed.
- Tool calls, after the model proposes them and before they execute.
- Final actions and side effects, such as sending an email or writing a file.
NeMo Guardrails names five rail types that map closely to this: input, dialog, retrieval, execution and output rails, as described in its README. The common mistake is to guard only point 1. Most serious agent incidents enter at point 2 and do their damage at points 4 and 5. Input vs output guardrails works through which check belongs where.
What are the open-source and managed options?
As of October 2026, the landscape splits into three groups: open-weight guard models you host, open-source frameworks that orchestrate checks, and managed services from cloud and security vendors.
| Option | Kind | License or access | Notes |
|---|---|---|---|
| Llama Guard 4 (12B) | Content safety model | Llama 4 Community License | Text and multi-image, released April 2025 |
| Llama Prompt Guard 2 (86M, 22M) | Prompt attack classifier | Llama 4 Community License | 512-token window, binary label |
| ShieldGemma, ShieldGemma 2 | Content safety models | Gemma terms | 2B, 9B, 27B text; 4B image |
| Qwen3Guard | Content safety models | Apache 2.0 | 0.6B to 8B, streaming variant, 119 languages |
| Granite Guardian 4.1 (8B) | Safety and grounding judge | Apache 2.0 | Bring-your-own criteria, released April 2026 |
| gpt-oss-safeguard (20B, 120B) | Policy-following safety reasoner | Apache 2.0 | You write the policy in the prompt |
| NeMo Guardrails | Framework | Apache 2.0 | Version 0.24.1, September 2026 |
| Guardrails AI | Framework | Apache 2.0 | Version 0.11.0, August 2026 |
| LlamaFirewall | Framework | See repository | Agent-focused scanners |
| Azure Prompt Shields, Bedrock Guardrails, Google Model Armor | Managed services | Commercial | Integrated with each cloud's model platform |
The details, including which projects are archived, are in open-source LLM guardrails compared. Two projects that used to appear in every list are now archived on GitHub: Protect AI's LLM Guard and Rebuff. Both still install, but neither is maintained.
The managed services differ mainly in where they plug in. Bedrock Guardrails can also run standalone through its ApplyGuardrail API. Google Model Armor screens prompts and responses and recommends separate templates for each. Cloudflare's AI Security for Apps, formerly Firewall for AI, runs at the network edge on JSON requests to endpoints you label. That edge model has its own trade-offs, covered in what is an AI firewall.
What can't guardrails do?
Guardrails are probabilistic filters around a probabilistic system. Be clear about the limits before you rely on one.
- They can be evaded. Classifiers are models, and models have adversarial inputs. The Prompt Guard 2 model card lists "vulnerability to adaptive attacks" as its first limitation, and the adaptive attacks paper shows how wide that gap can be.
- They can be injected. An LLM-based guard reads the attacker's text too. The Llama Guard 4 card notes that it "may be susceptible to adversarial attacks or prompt injection attacks that could bypass or alter its intended use."
- They only see what you route through them. A guardrail on the chat endpoint does nothing for the nightly batch job that summarizes support tickets with the same model.
- They do not fix excessive permissions. If an agent can delete production data, a guardrail that catches 99 percent of malicious requests still leaves the 1 percent. Reducing what the agent can do beats detecting what it should not do.
- They have policy mismatch. A safety classifier enforces the taxonomy it was trained on. Meta's own card for Llama Guard 3 notes that comparing guard models is hard because "each model is built on its own policy."
The strongest designs combine detection with architecture. Google DeepMind's CaMeL separates control flow from untrusted data so injected text cannot change which tools run, and solved 77 percent of AgentDojo tasks with provable security against 84 percent for an undefended system. The design patterns paper by Beurer-Kellner and colleagues catalogs similar patterns. A guardrail is a layer in that design, not a substitute for it.
How do you choose LLM guardrails?
Run this process before you pick a vendor or a model.
- List your risks. Write down what a bad day looks like: a leaked customer record, a refund issued to an attacker, an offensive reply in a screenshot, a hallucinated legal claim. Map each to an OWASP category. This tells you which guardrail families you need and which you can skip.
- Map your trust boundaries. Mark every point where untrusted text enters the context and every point where model output causes an effect. Each one needs a decision about which check runs there.
- Assemble an evaluation set from your own traffic. Public benchmarks measure someone else's distribution. Collect a few hundred benign samples from real usage, including the awkward ones (security questions, medical terms, code), and a set of attacks relevant to your application. The prompt injection benchmarks post lists public sets to borrow from.
- Measure three numbers for each candidate. Catch rate on your attacks, false positive rate on your benign traffic, and p95 latency at your expected load. A guard with a great benchmark score and a 5 percent false positive rate on your users will be turned off within a month. Guardrail false positives explains how to measure this properly.
- Decide failure behavior. For each check, decide what happens when it times out or its service is down. Fail closed for checks that protect data or actions. Fail open, with logging, for quality checks.
- Set a latency budget. Decide how many milliseconds the guardrail layer may add at p95, then design to it with parallel execution and tiering. Guardrail latency covers the techniques.
- Plan for maintenance. Attacks change monthly. Decide who updates models and rules, how you re-run the evaluation set, and how you learn about misses in production.
Questions to ask any guardrail, open or commercial
- What exactly does it detect, and what does it explicitly not detect?
- What was it evaluated on, and how close is that to my traffic?
- What is the false positive rate at the threshold I would actually use?
- What does it add to p50 and p95 latency, and where does it run?
- Does my data leave my environment, and is it stored?
- Does it handle streaming responses, multiple languages and long inputs?
- How do I tune it, and how do I find out when it misses?
- When was it last updated, and who maintains it?
The last question matters more than it looks. The archived status of two once-popular open-source projects is a reminder that a guardrail is a dependency with a maintenance cost, and build vs buy is a real decision rather than a default.
A reference architecture for a typical agent
For an agent that reads user requests, retrieves documents and calls tools, a reasonable starting point looks like this:
- On user input: a fast prompt attack classifier and a sensitive data pass that redacts or tokenizes personal data before the model sees it.
- On retrieved and tool-returned content: the same prompt attack check, tuned for documents, plus provenance tagging so the model and later checks know what came from outside.
- On tool calls: deterministic validation against an allowlist and the tool's schema, plus a policy for high-impact actions that requires confirmation.
- On output: a content safety check if the application is public-facing, a grounding check if answers must be supported by sources, and output encoding before any model text reaches a browser, shell or SQL engine. Improper output handling covers that last step.
- Everywhere: logging of every decision with enough context to replay it, and a dashboard of block rates so a sudden spike, either an attack or a broken guard, is visible within hours.
What to do next
Pick one application, run steps 1 and 2 of the selection process, and write down the trust boundaries. That map tells you more about the guardrails you need than any comparison table.
If you want the request-path checks without assembling them yourself, FrostWolf Guard wraps the provider call you already make in TypeScript or Python, blocks prompt injection and unsafe tool calls in the request path, and its Cloak feature keeps personal data out of the model. There is a free SDK tier.
Whatever you choose, measure it on your own traffic, decide its failure mode in advance, and keep the architecture doing most of the work. Guardrails reduce risk. Least privilege removes it.
Frequently asked questions
What is the difference between guardrails and model alignment?
Alignment is trained into the model's weights, so it travels with the model and you cannot inspect or change it at runtime. A guardrail is a separate check in your application that you configure, log and tune. You want both, because alignment can be bypassed by a jailbreak and a guardrail only sees what you route through it.
Are LLM guardrails enough to stop prompt injection?
No. Detectors reduce the attack rate, but published adaptive attacks have bypassed most defenses tested against them. Treat a guardrail as one layer and pair it with least-privilege tools, validation of tool calls, and output handling that never trusts model text.
Do guardrails add latency?
Yes, every check in the request path adds some. Small classifiers add milliseconds to tens of milliseconds on a GPU, while LLM-based judges add hundreds of milliseconds or more. Running checks in parallel with the main call and keeping the expensive ones for risky paths keeps the cost down.
Should I use an open-source guardrail or a managed service?
Open-source models and frameworks give you control and keep data in your environment, but you own hosting, tuning and updates. Managed services remove that work and usually update faster, at the cost of sending traffic to a vendor. Many teams combine a framework they control with one or two hosted detectors.
What should a guardrail do when it fails or times out?
Decide this explicitly and per check. For checks that protect against data loss or unsafe actions, fail closed and refuse the request. For low-stakes quality checks, failing open and logging the miss is often acceptable.