Yeda AI Tips · #049

Guardrails Are Two Checkpoints, Not One

Someone types a request into your AI feature, and the model just answers — no friction, no check, nothing standing between "the user asked" and "the model did." That's what running with zero guardrails looks like. The fix isn't one filter bolted on somewhere. It's two.

The problem: one filter covers half the risk

Most teams that add "a guardrail" add exactly one check, usually right before the model responds, and call it done. But a single checkpoint only catches failures on one side of the exchange. It misses the failures that happen on the other side entirely.

Guardrails split naturally into two categories, based on when they run relative to the model call:

These aren't redundant. An input check can't see what the model is about to say — it only knows what the user asked. An output check can't undo the fact that the model already processed a malicious prompt — it can only catch what leaks out the other end.

Why it works: each side has a distinct job

Input guardrails are your first line of defense. Common patterns include:

Output guardrails catch what got through, or what the model produced on its own even from a clean input:

The reason both matter: an input guardrail can be clean and the model can still produce an unsafe answer. And an output guardrail alone means you've already spent a model call — and potentially exposed the model to a malicious prompt — before catching anything.

How to build it

You don't need a heavyweight framework to start. Each guardrail is just a small function, a list of patterns, or a rubric evaluated by a lightweight classifier (or a cheaper LLM call). The shape is simple:

request → [input check] → model → [output check] → response

  1. Write the input check first. Start with the highest-value catches: an off-topic filter, a PII detector, a jailbreak pattern check.
  2. Write the output check next. At minimum, run a content-safety classifier over the generated response before it's returned. Add a schema-specific leak-detection pass if your feature can expose structured data.
  3. Wire both into the request path, not as an afterthought — the output check should block the response from reaching the user, not just log a warning.
  4. Log every block, on both sides. Every blocked input previews the next attack pattern; every blocked output shows where your model's failure modes actually are.

A concrete demo pattern: a request the topic guardrail should reject returns something like "Blocked. Topic not allowed"; a request that trips the toxicity filter returns "Unsafe content detected"; a request carrying sensitive data returns "Sensitive information detected". All three live on the input side and never touch the model. The output side runs its own, separate content check on whatever the model actually produces.

Pitfalls

Power tricks

Resources

Shipping an AI feature? Yeda AI designs, audits, and ships production LLM systems.

Talk to us · Read the blog