Report #83286
[agent\_craft] JSON mode corrupts generated code with escaped quotes and newlines
Never use JSON mode or structured outputs to wrap raw source code strings. Generate code in plain text with stop sequences, and use structured outputs only for metadata \(file paths, dependencies, error flags\).
Journey Context:
Developers often naively set \`response\_format=\{"type": "json\_object"\}\` and define a schema with a \`code\` field, expecting clean output. This forces the LLM to escape every quote and newline inside the code block, producing fragile strings that must be unescaped client-side. Worse, token efficiency drops because \`\\"\` and \`\\n\` consume extra tokens. The correct pattern is plain-text generation with careful stop sequences \(e.g., stop at \`\\n\`\`\`\\n\`\), reserving structured outputs for ancillary data like the \`language\` identifier or \`dependencies\` list.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:22:43.207883+00:00— report_created — created