What guardrails does a production agent loop need?
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
Guardrails fall into three groups: bounding the loop, gating the actions, and constraining the blast radius. A loop with none of them is a demo.
Full worked answer with diagram
Guardrails fall into three groups: bounding the loop, gating the actions, and constraining the blast radius. A loop with none of them is a demo.
Bounding the loop:
- Max iterations and max wall-clock time - non-negotiable; every agent eventually meets a task it can't finish and must fail cleanly instead of spinning.
- Token/cost budgets per run and per user/tenant. Runaway trajectories are a real billing incident class.
- Degenerate-behaviour detection: hash tool calls and flag identical repeats; track a no-progress counter; on trigger, inject corrective feedback or abort. Cheap and catches the most embarrassing failure mode.
Gating the actions - the core design principle is that reversibility determines autonomy:
- Permission tiers: reads auto-approved; writes to scoped resources allowed with logging; irreversible or externally visible actions - send email, delete data, spend money, post publicly, modify permissions - require human approval, always, regardless of how confident the model sounds.
- Human-in-the-loop gates placed at plan level ("approve this 6-step plan") and at dangerous-action level. Plan-level gates are cheap; per-action gates are the backstop.
- Allowlists/denylists enforced in the executor, not the prompt: which shell commands, which hosts, which database operations. Prompt-level restrictions are suggestions; executor-level restrictions are controls.
- Argument validation and dry-runs for high-risk tools (e.g., show the SQL and row-count estimate before executing a delete).
Constraining blast radius:
- Least-privilege credentials per tool (the agent's GitHub token doesn't need org admin).
- Sandboxed execution for code and shell.
- Idempotency keys on side-effectful tools so harness retries can't double-execute.
- Kill switch and full audit log - when something goes wrong you need to stop it now and reconstruct what happened.
Sequencing matters in the answer: executor-enforced controls first, prompt-based behavioural nudges second - never the reverse.
Worth sketching. Putting every guardrail on one action's path shows they are stages in the executor, not lines in the prompt.
flowchart TD
A["Model proposes an action"] --> B{"Allowlist and<br/>schema check"}
B -->|"blocked"| C["Actionable error<br/>returned as a tool result"]
B -->|"allowed"| D{"Reversible?"}
D -->|"yes"| E["Execute with<br/>least-privilege credentials"]
D -->|"no"| F["Human approval gate"]
F --> E
E --> G{"Budget, clock or<br/>repeat detector tripped?"}
G -->|"no"| A
G -->|"yes"| H["Abort, log,<br/>report partial results"]
What a good answer covers
- Guardrails fall into three groups: bounding the loop, gating the actions, and constraining the blast radius
- A loop with none of them is a demo
- Bounding the loop: - Max iterations and max wall-clock time - non-negotiable; every agent eventually…
- Runaway trajectories are a real billing incident class
- Cheap and catches the most embarrassing failure mode
Key terms: Bounding the loop · Max iterations · max wall-clock time · Token/cost budgets · Degenerate-behaviour detection · Permission tiers · Human-in-the-loop gates · Allowlists/denylists · Argument validation and dry-runs · Constraining blast radius
In the glossary: Guardrails · Tool call
Interviewer follow-ups to expect
How do you keep approval gates from destroying UX on a 50-step task?
Who approves when the agent runs unattended overnight?
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