Where should a rule live? Prompts vs code vs permissions
A visual guide to enforcing rules in Claude systems: what belongs in prompts, in handler checks and hooks, in permissions, and with a human.
In 30 seconds
Instructions in a prompt or CLAUDE.md are guidance: usually followed, never guaranteed.
Hooks and checks in tool handlers run every time, so they can enforce rules.
Permissions and credentials make forbidden actions impossible, whatever the model does.
Irreversible or high-stakes actions can require a human decision.
The stronger the consequence of breaking a rule, the further right it belongs.
The question behind many exam answers
A large share of architecture questions boil down to one decision: where should this rule be enforced? The options usually include a prompt instruction, a check in code, a permission setting and a human. Picking the right layer depends on what happens if the rule is broken.
Guidance: prompts and memory files
System prompts and CLAUDE.md are the right place for tone, priorities, conventions and preferences. Claude follows them most of the time, and explaining the reason behind a rule makes it follow them better. But "most of the time" is not good enough for money, privacy or safety.
Enforcement: handlers and hooks
If refunds above $500 need approval, the refund tool's handler should check the amount and create an approval request instead of paying. In Claude Code and the Agent SDK, hooks run before or after tool calls and can block or transform them. These checks run every time, regardless of what the conversation says.
Impossibility: permissions and credentials
The strongest guarantee is that the forbidden action cannot happen at all. An analytics MCP server that connects with a read-only database role cannot delete data, even if a tool is misused or a prompt is manipulated. Identity works the same way: the customer ID for a lookup comes from your authenticated session, not from what the user types.
Judgement: a human
Some actions are legitimate but consequential — a large refund, a production deployment, a message to every customer. Requiring approval keeps a person in the loop where a mistake would be expensive or impossible to undo.
Exam pattern: if an option enforces a hard rule only with a prompt sentence, look for the option that moves it into code or permissions.
Part of Domain 1: Agentic Architecture & Orchestration (27% of the exam). Explanations are our own, checked against Anthropic's documentation on November 22, 2026.
Common traps
Trap
Why it fails
Do this instead
"Never do X" in the system prompt
Prompts are probabilistic; injected text can override them
Check in the handler or a hook
Model supplies the customer ID
A manipulated chat can fetch someone else's data
Bind IDs to the authenticated session
Describing a tool as read-only
A description is not access control
Use a read-only credential
Check yourself
Two original practice questions on this lesson. Try them before opening the answers.
Check yourself 1
Scenario: Customer support resolution agent
Company policy says refunds above $500 require human approval. The agent has a refund tool. Which implementation enforces this most reliably?
A. Check the amount in the refund tool's handler and create an approval request above $500
B. Give Claude a check_policy tool and instruct it to call that tool before every refund
C. State the $500 rule in the system prompt and add few-shot examples of correct escalation
D. Set temperature to 0 so Claude applies the $500 rule the same way on every request
Show answer and explanation
Answer: A. Business rules with financial impact belong in deterministic code where the side effect happens. A check in the tool handler (or a pre-tool hook) cannot be skipped, whatever the conversation says. Prompt rules and examples are probabilistic; a check_policy tool still depends on Claude choosing to call it; temperature 0 makes output more repeatable, not guaranteed.
Check yourself 2
Scenario: Customer support resolution agent
Your support agent must never reveal one customer's data to another. Identity is established by your login system before the chat starts. Where should the customer ID used in data lookups come from?
A. From the most recent customer ID mentioned in the conversation, validated by format
B. From the authenticated session, attached by your application server-side to each lookup
C. From the chat, where Claude extracts the ID the customer gives when asked to confirm it
D. From the system prompt, where your app inserts the ID for Claude to copy into tool calls
Show answer and explanation
Answer: B. Authorization must not depend on model output. Binding lookups to the authenticated identity in your application means even a manipulated conversation ("I am customer 123") cannot fetch someone else's records. If Claude supplies or copies the ID, the security boundary is only as strong as the prompt.