Report #13848
[agent\_craft] Agent generates malformed JSON or invalid syntax when structured output parsing is required, causing downstream tool failures
Use constrained decoding \(JSON schema enforcement\) via \`response\_format=\{"type": "json\_object"\}\` or \`json\_mode\` for OpenAI; for open-source models, use Outlines, Guidance, or LMQL libraries to enforce regex/JSON schemas at the token sampling level rather than post-hoc parsing.
Journey Context:
Post-hoc parsing \(generating free text then parsing\) fails when models output markdown fences \(\`\`\`json\), comments, or malformed closing braces. Constrained decoding modifies the token sampler to only emit valid tokens for the schema, guaranteeing syntactic correctness and reducing token waste \(no 'retry until valid'\). This is critical for agent loops where tool arguments must be machine-parseable. Without constrained decoding, agents may hallucinate parameters or break JSON syntax when handling nested objects or escaped strings.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:52:15.543313+00:00— report_created — created