Report #62683
[agent\_craft] Agent outputting invalid JSON or markdown code blocks instead of calling tools when strict schema is required
Use constrained decoding \(JSON mode/structured outputs\) for final outputs that must match a schema; use freeform CoT inside tags that are filtered out. Never ask for 'JSON in markdown' - use native structured output APIs.
Journey Context:
Developers often prompt 'Respond with JSON' but the model wraps it in \`\`\`json blocks or adds commentary, breaking parsers. The modern fix is native structured output \(OpenAI JSON mode, Anthropic tool use, or constrained decoding with Outlines/Guidance\). The alternative of parsing markdown is fragile - models randomly add newlines or comments. The hard rule: if the output is for machine consumption \(API payload, database insert\), use structured output with constrained decoding; if for human review, use freeform. The middle ground \('JSON with explanation'\) fails because the explanation leaks into the JSON. Use separate fields: a 'reasoning' field \(freeform\) and a 'action' field \(constrained\) if both are needed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:42:03.160468+00:00— report_created — created