What is the difference between input guardrails and output guardrails, and why do you need both?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Input guardrails screen the request before it reaches the model. Output guardrails screen the response before it reaches the user or a downstream system. They catch disjoint failure sets, which is why you need both.
Full worked answer with diagram
Input guardrails screen the request before it reaches the model. Output guardrails screen the response before it reaches the user or a downstream system. They catch disjoint failure sets, which is why you need both.
Input side: PII detection and redaction, off-topic or out-of-scope classification, banned content, obvious injection patterns, length and rate caps. Cheap, and it saves you the model call entirely when it fires.
Output side: schema validation, groundedness or citation checking against the provided sources, PII leakage, toxicity, policy compliance, and verbatim-system-prompt detection.
Neither substitutes for the other. An input filter cannot catch a hallucination, because the hallucination does not exist yet. An output filter cannot prevent a prompt injection from having already fired a tool call halfway through the turn, which is why agents need a third layer: action gating at the tool boundary, where the irreversible operation is authorised in code.
Going further: follow-up territory
Design points worth raising:
- Layer by cost. Regex and small classifiers first, a small model next, an LLM judge only for the ambiguous remainder. Running a frontier-model judge on every request doubles your cost and latency for a check that a 100ms classifier handles.
- Latency. Input guardrails sit on the critical path. Run independent checks in parallel, not in a chain.
- Streaming is the hard part. If you stream tokens to the user, an output guardrail either buffers the whole response (destroying time-to-first-token, the thing streaming existed for) or checks incrementally and must be able to retract text already shown. Most teams buffer for high-risk surfaces and stream on low-risk ones.
- Fail open or closed is a product decision per check, and should be explicit. A toxicity classifier timing out on a support bot probably fails open; the same timeout on a medical surface does not.
And measure them: every guardrail has a false positive rate that shows up as a broken product.
Worth sketching. The third box is the point: it shows why input and output checks alone still leave a tool call unguarded.
flowchart LR
A["Request"] --> B["Input checks:<br/>PII, scope, injection patterns"]
B -->|"blocked"| C["Refuse, model never called"]
B -->|"pass"| D["Model"]
D --> E["Tool call"]
E --> F["Action gate:<br/>authorisation in code"]
D --> G["Output checks:<br/>schema, groundedness, leakage"]
G -->|"fail"| H["Retry or block"]
G -->|"pass"| I["User"]
What a good answer covers
- Input guardrails screen the request before it reaches the model
- Output guardrails screen the response before it reaches the user or a downstream system
- They catch disjoint failure sets, which is why you need both
- Input side: PII detection and redaction, off-topic or out-of-scope classification, banned content,…
- Cheap, and it saves you the model call entirely when it fires
Key terms: Input side · Output side
In the glossary: Guardrails · Hallucination · Prompt injection · Tool call · Judge (LLM-as-judge)
Interviewer follow-ups to expect
How would you keep an output guardrail from destroying your streaming latency?
- Layer by cost. Regex and small classifiers first, a small model next, an LLM judge only for the ambiguous remainder. Running a frontier-model judge on every request doubles your cost and latency for a check that a 100ms classifier handles.
- Latency. Input guardrails sit on the critical path. Run independent checks in parallel, not in a chain.
- Streaming is the hard part. If you stream tokens to the user, an output guardrail either buffers the whole response (destroying time-to-first-token, the thing streaming existed for) or checks incrementally and must be able to retract text already shown. Most teams buffer for high-risk surfaces and stream on low-risk ones.
- Fail open or closed is a product decision per check, and should be explicit. A toxicity classifier timing out on a support bot probably fails open; the same timeout on a medical surface does not.
What false-positive rate would you accept on an off-topic classifier, and how would you measure it?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep