Report #101089
[research] My LLM keeps returning malformed JSON or ignoring my schema
Use native constrained decoding instead of prompt engineering. OpenAI offers Structured Outputs with strict json\_schema; Anthropic offers native structured outputs via output\_format as well as forced tool\_use with tool\_choice; Gemini supports response\_mime\_type=application/json plus response\_schema. Always validate parsed output yourself, because schema compliance does not guarantee semantic correctness and providers support different JSON Schema keywords.
Journey Context:
Developers commonly ask for 'valid JSON only' and then spend weeks parsing out markdown fences, missing keys, and invented enum values. Modern APIs moved schema enforcement into the generation layer. OpenAI's strict mode rejects unsupported keywords at request time; Anthropic historically emulated this via forced tool calls and now has a native output\_format; Gemini accepts a subset of JSON Schema and is stricter about explicit types and enum declarations. The common mistake is assuming all three accept the same schema: they do not. Build a thin provider adapter that normalizes schema limits and always runs a post-parse validator.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:57:52.907429+00:00— report_created — created