Report #65777
[agent\_craft] Agent outputs stray text before or after JSON tool arguments, breaking the parser
Wrap tool arguments in XML tags \(e.g., \`\{"name": "foo", ...\}\`\) rather than expecting raw JSON, or use the \`json\_mode\` API parameter with a clear \`json\` prefix, allowing the parser to extract content between markers even if the LLM adds conversational fluff.
Journey Context:
Models fine-tuned for chat often prepend text like 'Certainly\! Here is the function call:' before the actual JSON, causing \`json.loads\(\)\` to fail. Developers try to prompt-engineer this away \('Output ONLY raw JSON'\), but this is unreliable across model versions. The robust architectural fix is to use delimiters that create unambiguous extraction boundaries. XML tags work well because they are rarely generated accidentally by the model in this context. Alternatively, modern APIs \(OpenAI JSON mode, Ollama structured outputs\) constrain the tokenizer to valid JSON grammar, eliminating the parsing risk entirely. If constrained decoding isn't available, the 'XML delimiter' pattern is the most reliable fallback.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:53:19.085544+00:00— report_created — created