CCA-F start here · Trap gym · Hook to clean up data

Hook to clean up data

Your tools return dates and statuses in different shapes: Unix timestamps, ISO 8601 strings, numeric status codes. Claude sometimes misreads them. The options offer to explain the formats in the prompt, to add a model, or to ask the tools' owners for a change. The trap is asking Claude to clean the data when plain code can do it, the same way every time, before Claude ever sees it.

D1 Agentic ArchitectureExam guide 1.5About 10 minutes

At a glance: use a PostToolUse hook to tidy mixed formats, such as dates and status codes, before Claude sees the result, instead of asking Claude to do it.

Start here: the post room

Three suppliers send invoices. One writes dates as 03/04, one as 4 March, one as a number of seconds. The accountant has to guess which is which, and now and then guesses wrong.

Tell the accountant. A note on the desk explains each supplier's habit. Mostly it works. On a busy Friday a date still gets misread.
Stamp it in the post room. Before any invoice reaches the accountant, the post room stamps it with one date format. The accountant never has to guess, and a new supplier only needs a new stamp.

Claude works the same way. A tool result is what a tool sends back after Claude calls it. A hook is your own code that the Agent SDK runs at a fixed point in the loop. A PostToolUse hook runs after a tool returns and before Claude reads the result, so it can rewrite that result: turn 1775037600 (a Unix timestamp, the number of seconds since 1 January 1970) into 2026-04-01T10:00:00Z (ISO 8601, the standard date-and-time text format), and status 3 into "paid_out". A PreToolUse hook runs at the other end, on the outgoing call, before the tool runs.

lookup_order1775037600 track_shipment2026-03-31T16:00Z get_refund"status": 3 three tools, three formats System prompt asks Claude to convert Claude reads what arrives PreToolUse hook sees the call only PostToolUse hook rewrites every result or a normalising subagent: same spot, plus a model call call result
The one question to ask: is the problem in what the tool returns, and could plain code fix it the same way every time?

Words in the question that tell you which side you're on

PostToolUse hook

  • “different formats”, “each source its own format”
  • Unix timestamps, ISO 8601, numeric status codes
  • “before the model sees”, “every tool result”
  • “strip a field”, “the team cannot change their responses”

Somewhere else

  • “the agent calls the wrong tool”: tool descriptions
  • “the rule must block an action”: PreToolUse
  • “a style or a tone”: the prompt

Try it: three tools, one customer question

A meal-kit support agent has three tools, owned by three different teams. lookup_order gives the weekly box's delivery date as a Unix timestamp. track_shipment gives the pantry box's arrival as ISO 8601. get_refund gives a numeric status code. Pick a customer, then pick how you handle the formats. The diagram above shows where your choice acts.

1. The customer

2. How you handle the formats

The customers, values and rates are made up and illustrative, chosen to show the shape. They are not measurements. The exam guide's point is that a PostToolUse hook transforms results before the model sees them, and that hooks are deterministic where prompt-based compliance is probabilistic.

Things to try: Asha + Do nothing: Claude guesses both the date and the status. Then Chen + System-prompt instruction: right for Asha and Ben, but Chen's timestamp slips. Then Chen + PostToolUse hook. Last, PreToolUse hook, the right family on the wrong side of the tool.

The traps

TrapWhat the wrong option looks likeWhy it loses
Only usually worksTell Claude in the system prompt how to read each format; add few-shot conversion examplesWorks most of the time, but Claude can still misread a timestamp. Code converts it the same way every time.
Slow and out of your handsAsk each team that owns a tool to change its output formatWorks eventually, but you don't control those tools, and the next new tool brings a new format.
Wrong hookUse a PreToolUse hookPreToolUse checks a call before it runs. The mess is in the result, which PreToolUse never sees.
OverbuiltAdd a separate normalising subagent, or a wrapper service per toolWorks, but adds a model call (or a service), cost and its own errors for a job a few lines of code do exactly.

Practice: three exam-style questions

Answer first, then open “Think it through”.

Rule to remember

Fix messy tool results in code on the way back, before Claude reads them.

Exam guide 1.5: “PostToolUse hooks intercept results for transformation before the model sees them.” and “Normalize heterogeneous formats (Unix ts, ISO 8601, numeric codes); block policy-violating actions (e.g., refunds > $500) and redirect to escalation.” Also 1.5: “Hooks give deterministic guarantees vs prompt-based probabilistic compliance.”

← All traps