1.5 — Agent SDK Hooks

CCAR-F Domain 1 · Task 1.5

What You Need to Know

An Agent SDK hook is code that intercepts a tool call or a tool result. Hooks are deterministic; the model is probabilistic. Hooks sit at the boundary between the model's decisions and the real world.

Two Types of Hooks

Hook When it runs What it can do
PreToolUse Before tool executes Block, modify arguments, redirect
PostToolUse After tool executes, before model sees result Transform / normalise the result

Key Concept: PostToolUse transforms data after execution. PreToolUse enforces policy before execution.

PostToolUse: Data Normalisation

Different tools return data in different formats (Unix timestamps vs ISO 8601 vs DD/MM/YYYY; numeric codes vs English strings). A PostToolUse hook converts every result to a consistent schema before the model processes it.

PreToolUse: Policy Enforcement

Examples:

  • Block process_refund when amount > $500 → escalate to human
  • Block transfer_funds until AML check has passed in this session
  • Pause approve_discount for discounts > 20% for manager approval

Decision Framework

Requirement Mechanism Guarantee
Must be followed 100% of the time Hooks Deterministic
Preferred but occasional deviation OK Prompts Probabilistic

Exam Traps

  • Using PostToolUse to block policy-violating actions (too late — action already happened)
  • Enhanced prompts as the solution for 100% compliance requirements
  • Leaving the model to normalise mixed data formats
  • Using PreToolUse to clean up tool results (wrong direction)

Check your understanding

Practice Scenario

An agent occasionally processes international transfers without the required AML checks. Compliance requires 100% enforcement. What is the correct approach?

Report issue

Log in to save your progress.

Sources