Report #14363
[agent\_craft] Agent generates malformed tool calls mixing JSON inside markdown code blocks
Use strict XML-like tags \(e.g., \{"arg": "val"\}\) or native function calling schemas in the system prompt; explicitly forbid markdown fences for tool calls and provide a regex-based parser example in the instructions.
Journey Context:
Most chat-tuned models default to wrapping JSON in \`\`\`json blocks because that is the training data format for display purposes, but this breaks structured parsers expecting raw JSON. While native function calling \(OpenAI/Anthropic function mode\) avoids this, many open-weight models only support text completion. XML tags are superior to raw JSON for these models because they provide clear boundaries that regex can parse reliably even if the model emits newlines or formatting inside the parameters. The alternative of 'just use stricter JSON validation' fails because the model has already left the generation context; recovery requires reprompting, whereas XML allows streaming extraction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:20:48.833523+00:00— report_created — created