Report #104120
[cost\_intel] Structured output retries \(JSON mode / function calls\) burn 2-10x tokens when the model repeatedly partial-fails the schema
Use constrained decoding \(Zod-to-JSON-Schema with \`strict: true\`, OpenAI Structured Outputs, or outlines\) so the first call cannot emit invalid JSON; if unsupported, downgrade to a cheaper model for a parse-and-repair pass rather than retrying the expensive model.
Journey Context:
Without constrained generation, a strong model can still emit malformed JSON or wrong enum values, especially on edge cases. Each retry sends the full conversation context again, so a 4k-token call that fails twice costs 12k tokens. The common wrong move is bumping temperature down or adding more examples; both increase tokens. The signature is high \`completion\_tokens\` with many \`finish\_reason=stop\` but parse errors. Constrained decoding removes the retry class entirely; parse-repair with a small model is the fallback when constrained decoding is unavailable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T05:16:02.336905+00:00— report_created — created