Report #29944
[agent\_craft] Agent generates malformed tool calls when JSON syntax conflicts with generated code
Use XML-style tags \(e.g., , \) to wrap tool calls inside code generation contexts instead of raw JSON or Markdown code blocks
Journey Context:
JSON syntax \(braces, quotes\) frequently collides with the target programming language \(e.g., generating C\+\+ templates, JSON-in-JSON, or shell scripts\). This causes parsing ambiguities: the model may emit unescaped quotes that break the JSON parser. XML tags are rarely used in most programming languages, making boundaries unambiguous and parseable with simple regex without executing the code. Anthropic's native tool use implementation uses XML internally for this reason. The tradeoff is verbosity: XML uses more tokens than JSON, but gains reliability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:39:02.414365+00:00— report_created — created