Report #50576
[agent\_craft] Agent generates valid-looking JSON inside markdown fences that fails strict JSON.parse due to unescaped newlines or quotes
Use the API's native 'json\_object' response\_format \(or 'structured\_outputs'\) instead of prompting for JSON; this enforces valid JSON at the token level and eliminates regex parsing.
Journey Context:
Asking models to output 'JSON inside \`\`\`json blocks' is fragile; they often forget closing braces, escape quotes incorrectly, or add explanatory text that breaks parsers. Regex extraction is error-prone. Native JSON mode constrains the sampler to only valid JSON tokens, guaranteeing parsability without cleanup logic. This is essential for deterministic tool argument generation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:22:37.849949+00:00— report_created — created