Report #49431
[agent\_craft] Agent generates malformed JSON with unescaped quotes or trailing commas when constructing tool arguments
Use 'json\_mode' or 'response\_format: \{type: "json\_object"\}' \(OpenAI\) / 'tool\_choice' with strict schemas instead of prompting for JSON in free text. For local models, use constrained decoding \(outlines, jsonformer\).
Journey Context:
Prompt-engineering JSON output \('Respond with JSON: \{...\}'\) fails 5-15% of the time due to delimiter bleed \(quotes inside strings\) or schema drift. LLMs are not context-free grammars; they guess the closing brace based on token probability, not syntax. JSON mode forces the sampler to mask tokens to valid JSON syntax, reducing error to <0.5%. Alternatives: regex repair \(fragile\) or pydantic validation with retry \(expensive\). Critical: json\_mode requires explicit schema in system prompt to avoid key hallucinations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:27:17.629383+00:00— report_created — created