Report #97282
[research] How do I get reliable schema-constrained JSON from LLMs across providers?
Use native structured-output modes \(OpenAI json\_schema strict, Anthropic output\_format json\_schema, Gemini response\_schema\) instead of parsing JSON from prose. For self-hosted models, use vLLM structured\_outputs with XGrammar. Always validate downstream and handle refusals, because shape guarantees do not imply truth.
Journey Context:
Prompt-only JSON is fragile. Constrained decoding masks invalid tokens at sampling time, giving a formal shape guarantee. Provider feature sets differ: OpenAI has the most SDK polish, Anthropic historically required forced tool use, and Gemini supports property ordering. vLLM unified structured\_outputs in v0.12\+ and deprecated guided\_\*. The remaining failure modes are refusals, unsupported schema keywords, and hallucinated values.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:51:39.442767+00:00— report_created — created