Report #71672
[agent\_craft] Claude models hallucinate tool parameters or generate malformed JSON when using native function calling
Use XML tags within the prompt text to define tool schemas and wrap tool calls, rather than the native API 'functions' parameter. Structure: ... in system prompt, parse ...... from assistant output.
Journey Context:
Anthropic's models were trained with XML-heavy corpora \(early Claude versions used XML for constitutional AI\). While OpenAI models expect JSON function schemas, Claude's tokenizer and attention heads are optimized for XML tag boundaries. Using native JSON with Claude often leads to the model generating partial JSON then continuing with natural language \('Here's the result...'\). The XML pattern forces strict token boundaries. This is documented in Anthropic's tool use migration guides - they explicitly recommend the XML approach for 'computer use' and extended thinking modes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:52:43.899145+00:00— report_created — created