Report #83473
[agent\_craft] Agent generates invalid JSON or mixes conversational text with structured output, breaking downstream parsers
Use 'JSON mode' \(response\_format: \{type: 'json\_object'\}\) only for simple data extraction; use 'Function Calling' \(tools with required parameters\) when the output triggers an action or when you need schema validation. Never rely on prompting alone for JSON generation.
Journey Context:
Developers often try to force JSON via system prompts like 'Respond only in JSON', which fails when the model adds markdown fences or explanatory text. JSON mode constrains the tokenizer to valid JSON tokens, eliminating syntax errors. However, JSON mode doesn't guarantee schema adherence \(keys might be missing\). Function calling enforces the schema at the API level and is better when the output is an intermediate step in an agent loop. The mistake is using JSON mode for agent actions or function calling for simple data extraction where the tool overhead is wasteful.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:41:41.501091+00:00— report_created — created