# 6.1 Layered guardrails & HITL

Input tripwires, human-in-the-loop approval and output checks as defense in depth.

1. Defense in depth: input, action and output guardrails.
2. Input tripwire blocks a prompt injection pre-inference.
3. A high-risk tool call pauses for HITL approval.
4. Approved; the output guardrail checks PII and releases.

- **Use when:** Untrusted input or irreversible side effects.
- **Avoid:** Approval fatigue, and combining the lethal trifecta in one agent.

```
if input_check(message).blocked:        # check 1
    return "Sorry, I can't help with that."

for call in agent.run(message):
    if call.tool.is_risky:              # check 2
        if not await ask_human(call):
            continue
    run(call)

return output_check(reply)              # check 3
```

## References

- [A practical guide to building agents](https://cdn.openai.com/business-guides-and-resources/a-practical-guide-to-building-agents.pdf) (OpenAI)
- [The lethal trifecta for AI agents](https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/) (Simon Willison)
- [Designing AI agents to resist prompt injection](https://openai.com/index/designing-agents-to-resist-prompt-injection/) (OpenAI)
- [Agents Rule of Two](https://ai.meta.com/blog/practical-ai-agent-security/) (Meta)
- [Guardrails](https://openai.github.io/openai-agents-python/guardrails/) (OpenAI)
- [Human-in-the-loop](https://openai.github.io/openai-agents-python/human_in_the_loop/) (OpenAI)
- [How we built Claude Code auto mode](https://www.anthropic.com/engineering/claude-code-auto-mode) (Anthropic)
- [Defeating Prompt Injections by Design](https://arxiv.org/abs/2503.18813) (Debenedetti et al.)
