Skip to content

LLM guardrails: where to put them and what they cost

LLM guardrails are checks outside the model that block or change requests and responses. Where to put them, which tools to use, and what they cost.

Published
Updated
Reading time
10 min read

In short

  • A guardrail is a check that runs outside the model, on the input or the output. It can block, redact, rewrite, or flag.
  • Build each check with the cheapest method that works: rules first, then a small classifier, then a second model acting as judge.
  • Input checks can run alongside the model call. Output checks force a choice between streaming and certainty, and agents add two more places to check: tool-call arguments and tool results.
  • Filters reduce prompt injection. Limiting what the model is allowed to do is what contains it.

A guardrail is a check that runs outside the model, on what goes in or what comes out, and can block, redact, rewrite, or flag it. It is code you control, which is the difference between a guardrail and an instruction.

A line in the system prompt that says "never reveal customer data" is a request. The model usually follows it. A guardrail that scans the output for account numbers and removes them is enforcement, and it works the same on the model's worst day.

InputInput checksModelOutput checksResponsePrompt injectionPII and secretsTopic and policyData leakageGroundingFormat and schemaOn a hit: block, redact, rewrite, or flag for review
Input checks protect the model and your budget. Output checks protect the user and your data.

What input and output checks catch

Input checks stop a bad request before you pay for it. Output checks stop a bad response before anyone reads it. They catch different problems.

On the input side you are looking for attempts to override the system prompt, personal data or secrets a user pasted that should not travel to a third-party API, and requests outside what the product is for.

On the output side you are looking for leaked secrets or system prompt text, claims the source documents do not support, and malformed output that downstream code would parse or execute. The 2026 OWASP Top 10 for LLM applications lists these as Sensitive Information Disclosure, Hidden Context Exposure, Misinformation, and Improper Output Handling.

Agents add two more places to check. Tool-call arguments are output that acts on the world, and tool results are input nobody typed. The MCP specification requires servers to validate tool inputs and sanitize outputs, and tells clients to validate results before the model sees them.

Check pointRuns onCatchesTypical action
InputThe user's message and attachmentsOverride attempts, pasted secrets and personal data, off-topic requestsBlock, redact
Retrieved contentDocuments and pages before they enter the promptHidden instructions, personal data in source filesStrip, flag
Tool-call argumentsWhat the model asks a tool to doWrites outside policy, data sent to outside services, unknown URLsBlock, ask a human
Tool resultsWhat a tool returns to the modelInjected instructions, secrets returned by an APIRedact, flag
OutputThe response before the user sees itLeaked secrets, unsupported claims, malformed JSONBlock, redact, rewrite

Three ways to build a check

A check can be a rule, a classifier, or a second model acting as judge. They trade speed for flexibility.

MethodAdded costGood atWeak at
Rules: regex, allowlists, schema validationNegligibleKnown patterns such as card numbers, API keys, invalid JSONAnything phrased in a new way
Classifier: a small model trained for one jobOne small model callBroad categories such as hate, self-harm, jailbreak attemptsPolicy specific to your business
LLM judge: a second model call with a rubricOne full model callNuanced policy written in plain languageSpeed, cost, and its own mistakes

Use the cheapest method that does the job. Start with rules for anything that has a fixed shape. Add a classifier for content categories. Keep the LLM judge for policy too specific for either.

You do not need to train the classifier yourself. Hosted services and open-source projects already cover the common categories, and the next section sets them side by side.

Guardrails tools compared

AI guardrails tools come in three forms: hosted APIs, open-weights safety models you host, and open-source frameworks that compose checks into a pipeline. Hosted APIs are the fastest to adopt and send your text to the vendor. Self-hosted options keep data in your network and leave the operating to you.

ToolFormWhat it checks
OpenAI moderationHosted API, freeHarm categories in text and images
Amazon Bedrock GuardrailsManaged serviceContent filters including prompt attacks, denied topics, word filters, sensitive information, contextual grounding, Automated Reasoning checks
Azure AI Content SafetyManaged servicePrompt Shields, harm categories, protected material, task adherence for agent tool use
Google Model ArmorManaged servicePrompt injection and jailbreaks, sensitive data, malicious URLs, safety filters, documents
Llama Guard 4Open-weights model, 12B, multimodalSafety categories you can customize, on user input and agent output
NVIDIA NeMo GuardrailsOpen-source frameworkInput, retrieval, dialog, execution, and output rails written in Colang
Guardrails AIOpen-source framework, Apache-2.0Validators from Guardrails Hub, combined into input and output guards

On AWS, start with Bedrock Guardrails: the ApplyGuardrail API runs a guardrail on any text without invoking a Bedrock model, and you can tag the part of a prompt to evaluate so system instructions and search results are skipped. Model Armor and Azure AI Content Safety can likewise screen traffic for models hosted elsewhere.

Pick by where your prompts may go. If they cannot leave your network, host Llama Guard or a framework. If they already go to a cloud provider, its service adds one call to a vendor you trust anyway.

What guardrails cost

Guardrails cost latency and false positives. Both are worth measuring from the first day.

Input checks do not have to slow down the response. Start the model call and the input check at the same moment, and cancel the call if the check fails. The user waits no longer on a clean request. You pay for a few tokens on each blocked one.

That shortcut is unsafe for agents. If the model can call a tool that changes something, run the input check first and wait for it.

Output checks collide with streaming. You have three options:

  • Buffer the full response, check it, then send it. This is certain, and the user watches a spinner.
  • Check in chunks, one sentence or paragraph at a time, and release each chunk as it passes. This adds a small delay.
  • Stream immediately and retract on a violation. This is fastest, and the user may see the text before it disappears.

Buffer anything regulated. Use chunked checking for general chat. Avoid retraction where a brief exposure is itself the harm.

Chunked checking has one gap: a secret split across two chunks passes both checks. Recheck the tail of each chunk with the next one.

False positives are the cost teams forget. Every legitimate request you block is a failure the user sees. Track the block rate per check, and review a sample of blocked requests every week. A check nobody reviews drifts toward blocking too much or too little.

How to measure a guardrail

Measure a guardrail like any classifier: how often it blocks good traffic, how often it misses bad traffic, and how much time it adds. You need real traffic for the first, a test set of attacks for the second, and per-check timing on the request trace for the third.

MetricHow to get itWhat it tells you
False positive rateLabel a weekly sample of blocked requestsHow much legitimate use the check costs
Miss rateRun a fixed set of known attacks and leaks against itWhether a model or threshold change weakened it
Added latencyp95 of each check's span, per routeWhether a check belongs on the request path or after it
Block rate by ruleCount decisions per check per dayDrift: a sudden rise usually means a broken rule, not an attack

Run the attack set whenever you change a threshold, model, or provider. An upgrade that halves false positives and quietly doubles misses looks like a win on every other dashboard. LLM evaluation covers how to build that test set.

Why filters do not stop prompt injection

Filters do not stop prompt injection because an attacker can always rephrase, and the model cannot reliably tell instructions from data.

OWASP separates two forms. In direct injection, the person typing supplies input that changes the model's behavior. In indirect injection, the model reads external content that carries instructions the user never saw: a web page, a document, an email, a tool response.

A classifier trained on known attacks will catch known attacks. Indirect injection arrives through content your system chose to fetch, in any wording, in any language.

So plan for one getting through, and decide in advance what it can reach. OWASP moved Excessive Agency up to third place in its 2026 list, which reflects where the damage now comes from. These controls limit it:

  • Give each tool the narrowest permission that works. A support agent needs to read orders. It does not need to issue refunds.
  • Require human approval before any action that writes, sends, or deletes. The MCP specification recommends a human be able to deny tool calls for this reason.
  • Keep secrets out of prompts. The model cannot leak what it was never given.
  • Validate model output before code acts on it. Treat it like form input from a stranger.

The MCP article covers the tool side of this in more detail, and the prompt injection article covers the attacks and the defenses that contain them.

Where to put them

Put baseline checks in the gateway and context-specific checks in the application.

The gateway sees every request from every team, so it is the right place for rules that apply to all of them: redacting personal data, content moderation, and a record of each decision. One implementation covers every caller, including the ones built next quarter. The gateway article describes that layer.

Bifrost, an open-source AI gateway by Maxim AI, shows what that layer looks like in practice. Its guardrails run on input, output, or both, and apply the same rules to MCP tool arguments and tool results. Secrets detection and custom regex rules, including a PII template, run inside the gateway with no extra provider call. For injection and content categories it calls providers such as AWS Bedrock Guardrails, Azure Content Safety, and Google Model Armor.

When an output rule can block, Bifrost holds the stream until the check finishes, which is the buffer option above made explicit. Its redaction modes also answer the logging problem in the next section: logs_only leaves live traffic raw and stores placeholders, and the mapping that reveals a value never leaves the gateway.

The application knows things the gateway does not: which documents were retrieved, what the user is allowed to see, what a valid answer looks like. Checks that depend on that knowledge, such as grounding an answer in its sources, belong there. The hallucination detection article shows how that check works.

A gateway only covers traffic that passes through it. Employees who paste data into personal chatbot accounts never reach your checks, which is the problem shadow AI describes.

Log every guardrail decision on the request's trace, including the passes. When a user reports a blocked request, you want the check, the score, and the input in one place.

Logs need their own redaction

A guardrail that redacts live traffic does not protect your logs if the raw request was written before the check ran. Personal data then sits in log storage and every trace backend it feeds. Decide what the logs see separately from what the model sees.

Redact everywhere when the data must not reach the model either. Leave live traffic raw and store placeholders when the model needs the real value, such as a delivery address, and log readers do not.

Redaction only covers what a check detects, so a value no rule recognizes reaches the logs untouched. Test it like an auditor: send a known test value, then search the log store and the trace backend for it. What to record on every request covers the rest of what not to store.

Frequently asked questions

What are AI guardrails?

AI guardrails are checks that run outside a model on its inputs and outputs. They block, redact, rewrite, or flag content such as injection attempts, personal data, leaked secrets, and policy violations. Unlike a system prompt instruction, a guardrail is code you control, so it holds whether or not the model complies.

What is the difference between AI guardrails and LLM guardrails?

In practice there is none, and vendors use the terms interchangeably. Both describe checks on what goes into and comes out of a language model. "AI guardrails" sometimes stretches to image moderation and agent tool calls, while "LLM guardrails" tends to mean text in and text out. The design questions, placement, and costs are the same either way.

Do guardrails add latency?

Yes, but not always on the critical path. Input checks can run in parallel with the model call and cancel it on failure. Output checks add delay in proportion to the text they hold back. Rules add almost nothing, a classifier adds one small model call, and an LLM judge adds a full call.

What is Amazon Bedrock Guardrails?

Amazon Bedrock Guardrails is a managed AWS service that applies content filters, denied topics, word filters, sensitive information filters, contextual grounding checks, and Automated Reasoning checks to prompts and responses. You can attach a guardrail to a Bedrock model call or run it on any text through the ApplyGuardrail API, which makes it usable with models hosted outside Bedrock.

Can guardrails stop prompt injection?

They reduce it, but they cannot stop it. A classifier catches attacks that resemble its training data, and attackers can rephrase without limit, especially through documents and tool results. Limit what a successful injection can do instead: narrow tool permissions, human approval for writes, and no secrets in prompts.

Sources

  1. 01OWASP Top 10 for LLM Applications 2026OWASP GenAI Security Project
  2. 02LLM01: Prompt InjectionOWASP GenAI Security Project
  3. 03ModerationOpenAI API docs
  4. 04Llama Guard 4Meta
  5. 05Amazon Bedrock GuardrailsAWS docs
  6. 06What is Azure AI Content Safety?Microsoft Learn
  7. 07Model Armor overviewGoogle Cloud docs
  8. 08NeMo GuardrailsNVIDIA docs
  9. 09GuardrailsGitHub
  10. 10ToolsModel Context Protocol
  11. 11GuardrailsBifrost docs
  12. 12RedactionBifrost docs