Report #6382
[agent\_craft] LLM generates malformed JSON/tool arguments with unescaped quotes or comments
Use constrained decoding \(grammar-based\) or prompt with 'Output MUST be a single valid JSON object with no markdown, no comments, and all strings double-quoted'; follow with regex validation and auto-retry with explicit error feedback
Journey Context:
Even with 'respond in JSON' instructions, models \(especially non-frontier ones\) emit markdown fences, trailing commas, or comments. Constrained decoding \(e.g., outlines library, jsonformer, or OpenAI's JSON mode\) guarantees syntax. Without grammar constraints, the regex validation loop is essential: catch -> feed error back -> retry. Alternative \(hoping for correct format\) fails ~15% of time on complex nested args; alternative \(function calling API\) is not available on all models/endpoints.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:52:38.064507+00:00— report_created — created