OtherAdvancedClaude Agent SDK
If tool order matters, enforce it in code
Block process_refund until get_customer has returned a verified ID: the prompt works almost always, the hook works always.
An instruction in the prompt gives probabilistic compliance; a hook or a precondition in your code gives deterministic compliance. When the mistake costs money, exposes data or breaks a policy, use the second. The precondition can redirect to the escalation flow instead of just rejecting.
Example
# Pseudocode for the Agent SDK PreToolUse hook
if call.name == "process_refund":
if not session.verified_customer_id:
return deny("Verify the customer with get_customer first")
if call.args.amount > 500:
return redirect_to_escalation(call)