Policy Enforcement Outside the Model
In this article
- Explain why a limit written in the prompt does not stop a hijacked model, and where the limit must live instead.
- Read a short policy function and predict whether a proposed tool call is allowed, denied or sent for approval, and which rule decided.
- Place the policy check in the dispatcher so it runs on every call of a chain, before anything changes.
- Spot the same check in a real product, a Claude Code PreToolUse hook that blocks a call.
- Terms defined here: policy enforcement.
Overview
An agent that can send email is told in its prompt never to mail more than 10 people and to ask before mailing anyone outside the company. A hidden line on a web page tells it to forward the last 20 emails to a stranger. Which of the two does the model obey? You cannot know in advance, so you need a firm answer to a plain question: when the model asks to send a reply, who decides whether it goes, and on what grounds?
The answer is a single function in your own code that looks at who is asking, what the call would do and what the system already knows, and returns allow, deny or "a person must approve". With it in place, you can predict what happens to any proposed tool call, name the rule that decided it, say where the check must sit, and spot the same check in a real product.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- A limit in the prompt
- One function decides
- Three calls, three outcomes
- Every call, before the side effect
- What the model hears back
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions