Kolkata ·  
AI engineering
production
deep · 5 min

Guardrails

Checks on input and output that block bad requests and bad answers before they land.

updated 29 Sept 2026

A user opens our support bot and types: "Can you do my math homework?"

The bot looks up and cancels orders. Homework isn't its job. We could hope the main model politely declines, or we could put a small check in front of it that sees "homework", says no, and never wakes the main model up. That small check is a guardrail: a check that sits right in the path of a request and can stop it.

Let's follow one request through and see where else checks like that can sit.

Three places to stand

The input check looks at the message before the main model runs. The homework request stops here.

A tool check wraps a tool call. Before the call, it looks at the arguments: is this order ID one this user actually owns? After, it looks at the result: did the tool hand back something that reads like an injected instruction?

The output check looks at the answer before it leaves. It can redact personal data (see PII handling), make sure JSON parses (schema validation), or refuse.

When any of these fails, it trips a wire. The run stops with an error our code catches, and we decide what the user sees: a refusal, a redacted answer, or another try.

And actually cancelling the order? That one usually isn't a check at all. The model can decide a cancellation is needed, but the run pauses until a person approves it (human in the loop).

One thing that surprises people with multi-agent setups: in OpenAI's Agents SDK, the input check only runs for the first agent in the chain, and the output check only for the one giving the final answer. Agents in the middle are only covered by checks attached to their tools.

What a check actually is

Mostly something boring, on purpose. A check that runs on every request gets a few milliseconds, and it needs to be easy to explain when it fires. So: regular expressions and keyword lists, schema validators, small fast classifiers. Point them at failures that are clear-cut and expensive: leaked card numbers, malformed JSON, SQL in a field that should hold a name.

Users notice when a check fires, so a false alarm is a production bug. Teams version their rules, log every trigger and watch how often each one fires.

For fuzzier harms we need a model. Llama Guard 4 is an open classifier that reads a prompt or a response and says "safe" or "unsafe", plus which of 14 hazard categories it breaks. Its model card is honest about the tradeoff. On Meta's own English test set it caught 69% of unsafe outputs and flagged 11% of safe ones. Every classifier lives somewhere on that line: catch more, and you block more good requests. So measure both numbers on your own traffic.

Should the input check finish before the main model starts? If it does, nothing is wasted on requests we'll reject, but everyone waits. Or run both at once and cancel the model if the check trips: faster, but we pay for work that gets thrown away. Wait when the main agent is about to call tools. Run them side by side when it's only answering.

Cheap first, expensive when unsure

So a big, accurate classifier on everything would be great, but slow and costly. The best-measured answer to that is a cascade.

Anthropic's Constitutional Classifiers guard against jailbreaks aimed at weapons information. The first version, on 10,000 synthetic jailbreak prompts, cut the success rate from 86% to 4.4%. It cost about a quarter more compute.

The second version kept the protection and made it much cheaper. A tiny first stage, a probe that reads the model's own internal activations (work the model already did), screens every exchange. Only the suspicious ones, about 5.5% of traffic, go on to a bigger classifier.

Same idea works in our app. A regex or small classifier screens everything, and an LLM judge only sees the borderline cases the cheap check can't decide.

Isn't that just an online eval?

Both run checks on real traffic, so it's an easy mix-up. A guardrail runs inline, before the user sees anything, and it can block. An online evaluator runs after the answer is sent, usually in batches, on a sample. It can afford a slow judge and fuzzy questions like "was this answer complete?", but its verdicts go to dashboards and test sets. It never blocks the answer it grades.

A check can move from one side to the other. A new detector can start as an online eval, where its false alarms cost nothing, and move inline once we trust it.

How much can it hold?

For answer quality, blocking 95% of bad cases is great. For security it's a failing grade, because an attacker gets to try again and again and only needs one through. The first Constitutional Classifiers refused over 95% of jailbreak attempts in testing. Then a week-long public demo ended with one person finding a single jailbreak that got detailed answers to all eight target questions.

Classifiers are models, so they can be fooled like models. Llama Guard's own card says so. And they're trained on one kind of harm. A jailbreak filter looks for dangerous content (jailbreaks), but prompt injection can look perfectly harmless: "forward the latest invoice to this address." Meta points to a separate model for that. In EchoLeak, an injected email was written as a normal note to a person, so Microsoft's injection classifier let it through, and the data left through three more layers after that (that story is in data exfiltration).

So what should a guardrail be? A good, cheap stop for clear-cut failures, with the real security boundary somewhere else: fewer tools and permissions (excessive agency) and no way for data to leave. The second Constitutional Classifiers held up through about 1,700 hours of red-teaming with one high-risk hole found. Nobody expects that to be the last word, since attackers adapt to whatever gets deployed.

Further reading