CONCEPT The gate sits between decision and effect
The model decides to call a tool by emitting a tool_use block. But the model
doesn't execute anything — your harness runs the tool. That gap is where a
permission gate lives: you intercept the tool_use before executing,
check it against a policy, and either run it or refuse. Because the manual loop (3.6) hands you every
tool_use before it acts, gating is a natural extension of the loop — not a new mechanism.
| Policy verdict | What the harness does | What the model sees next turn |
|---|---|---|
| Allow | Run the tool immediately | The real tool_result |
| Confirm | Ask a human; run only on approval | Result if approved, else a denial tool_result |
| Deny | Never run it | An explanatory tool_result so it can adapt |
send_email, delete, external POSTs, and
payments stop at the gate. Which is which is the reversibility axis of 5.4.CONCEPT Deny with a reason, not with silence
When you refuse a call, don't just drop it. Return a tool_result that
explains the denial. The agent is stateless — the only way it learns "that path is blocked" is by
reading the result you feed back. A good denial message lets the model adapt: pick a
different tool, ask the user, or finish gracefully. A silent failure makes it retry the same blocked call.
DIAGRAM The confirmation gate
side-effecting?"} P -->|"reversible (read/glob/grep)"| R["🟢 Run tool"] P -->|"irreversible / side-effecting"| C{"Human confirms?"} C -->|approve| R C -->|deny| D["🟠 Explanatory tool_result
'Denied: needs approval'"] R --> RES["tool_result → append → loop"] D --> RES RES --> L["Re-send transcript (stateless)"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#fff3cd,stroke:#ffc107,color:#856404; classDef deny fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class R ok; class C,P gate; class D deny;
CODE A gate around tool execution
Intercept each tool_use, consult the policy, and either execute, confirm, or deny with an
explanation. Note the denial still becomes a tool_result so the loop continues cleanly.
# Which tools are side-effecting / irreversible → must be gated (see 5.4). GATED = {"send_email", "delete_file", "charge_card", "http_post"} def handle_tool(block): # Intercept BEFORE executing — this is the gate. if block.name in GATED: if not confirm(f"Approve {block.name}({block.input})?"): # DENY WITH REASON so the agent can adapt, not silently drop it. return f"DENIED: '{block.name}' needs human approval and was refused. " \ "Try a reversible alternative or ask the user." return run_tool(block.name, block.input) # allowed → execute # In the manual loop: build tool_result blocks from the gate's verdict. tool_results = [] for block in resp.content: if block.type == "tool_use": tool_results.append({ "type": "tool_result", "tool_use_id": block.id, "content": handle_tool(block), }) messages.append({"role": "user", "content": tool_results}) # re-send, loop continues
TRADE-OFFS Where to draw the gate line
✅ Gate more aggressively
- Smaller blast radius; nothing dangerous runs unreviewed
- Clear audit trail of approvals
- Safer for irreversible / regulated actions
⚠️ Gate more aggressively
- More human interrupts → slower throughput
- Approval fatigue; humans rubber-stamp
- Loses the point of automation if over-applied
EXAM TRAPS
tool_result so the stateless agent can adapt. A silent drop makes it retry.tool_use becomes execution.PRACTICE
Q1 · Where exactly does a confirmation gate intercept the call?
Between the model's tool_use block and your harness executing that tool — in the
manual loop, before run_tool runs. That's the only point where you can approve,
deny, or modify the action before it takes effect.
Q2 · A gate denies send_email. What must you send back, and why?
An explanatory tool_result tied to the same tool_use_id, e.g.
"Denied: email requires approval." Because the API is stateless, the model only learns the action was blocked
by reading that result — enabling it to adapt instead of blindly retrying.
Q3 · Allow-list vs. block-list for the gate — which is safer, and why?
Allow-list (deny-by-default). With a block-list, any newly added tool you forget to list runs unguarded. With an allow-list, an unclassified tool is gated until you explicitly approve it — a forgotten tool fails safe.