Report #39160
[cost\_intel] Using XML tool formatting for Claude structured outputs instead of JSON mode
Use Claude's JSON mode \(tools with strict schema\) instead of XML formatting for nested structured outputs. XML tags add 25-40% token overhead vs JSON for deep nesting \(>3 levels\). For a 50-field extraction schema, XML output costs $0.45 per 1k requests vs JSON $0.12 per 1k \(3.75x savings\). Reserve XML only when output requires conditional logic \(if/then branching\) that JSON schemas cannot express.
Journey Context:
Early Claude versions used XML for tool use, leading to legacy defaults. XML is more robust for complex conditionals \(e.g., 'if field X exists, explain Y'\), but for pure data extraction, JSON's token efficiency is dramatic. The 'quality degradation' is JSON's stricter schema adherence vs XML's flexible tagging—if your downstream parser needs conditionals, JSON may fail where XML succeeds. Critical: JSON mode requires explicit schema in tool definition; omitting 'required' fields silently allows hallucinated keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:12:20.046844+00:00— report_created — created