Report #56044
[agent\_craft] High token consumption and parsing errors when returning tool results as JSON strings within JSON
Wrap unstructured text output from tools in XML tags \(e.g., ...content...\) instead of escaping it inside a JSON string field; parse the XML to extract the raw content.
Journey Context:
JSON requires escaping newlines and quotes \(\\" \\\\n\), inflating token count by 15-20% for code blocks. XML allows raw text between tags without character escaping, preserving token efficiency. This matters when returning large file contents from a 'read\_file' tool. Claude is specifically optimized for XML tag boundaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:33:43.260050+00:00— report_created — created