Study FAQ
How should I normalize tool results in a Claude Agent SDK workflow?
Also asked as 2
- How can an Agent SDK result adapter preserve timestamp units, status meanings, and errors?
- What should I retain when converting different tools' outputs into a common format?
Answer
Normalize from each tool's documented contract, and retain the raw result, tool identity, and any conversion failure. A common representation is useful only when it preserves the meaning of the original data.
For timestamps, establish whether a numeric value means Unix seconds or milliseconds. Require a timezone or offset for text that must identify an instant. Convert an established instant to the chosen representation, such as UTC; leave an ambiguous local time unresolved. For status codes, use a mapping specific to the source tool. An unfamiliar code remains unknown rather than becoming success.
Keep execution and normalization outcomes separate. A tool may execute successfully but return a timestamp that cannot be interpreted. A timeout is an execution failure, not an empty successful result. A useful application-owned record includes the source tool, raw value, declared format, normalized value, and conversion status.
Place pre-action enforcement before dispatch. Use post-result processing for data the tool has already returned. In the current Agent SDK hook contract, PostToolUse can append additionalContext or replace output with updatedToolOutput for built-in and MCP tools; the older updatedMCPToolOutput applies only to MCP output. Match the fields to your installed SDK. An executor wrapper can also normalize its own return value.
Test a valid conversion, missing or malformed time, absent timezone, unknown status, and execution failure. Inspect what the consumer actually receives and preserve the failure if delivery or conversion fails. Post-processing cannot undo an external action.
Full explanation
Apply Agent SDK hooks for tool call interception and data normalization
Learning material · CCAR-F
Read the full explanation