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
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.
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.
- Yes, the result is messy (mixed dates, numeric codes, a field to strip): a PostToolUse hook that rewrites the result before Claude reads it.
- No, the problem is an action (a refund over the limit must not run): a PreToolUse hook that blocks the call.
- No, Claude picks the wrong tool: that's tool descriptions, not a hook.
- You don't own the tools: that's exactly why the fix goes in your hook, not in their API.
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.
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
| Trap | What the wrong option looks like | Why it loses |
|---|---|---|
| Only usually works | Tell Claude in the system prompt how to read each format; add few-shot conversion examples | Works most of the time, but Claude can still misread a timestamp. Code converts it the same way every time. |
| Slow and out of your hands | Ask each team that owns a tool to change its output format | Works eventually, but you don't control those tools, and the next new tool brings a new format. |
| Wrong hook | Use a PreToolUse hook | PreToolUse checks a call before it runs. The mess is in the result, which PreToolUse never sees. |
| Overbuilt | Add a separate normalising subagent, or a wrapper service per tool | Works, 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
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.”