Report #103062
[research] How do I get reliable structured JSON / tool output from LLMs across providers?
Prefer native constrained decoding: OpenAI Structured Outputs \(response\_format json\_schema strict\), Anthropic structured outputs / strict tool use, Gemini JSON-schema mode, or vLLM/XGrammar/Outlines/lm-format-enforcer for self-hosted models. Always validate with Pydantic/Zod after parsing; schema enforcement guarantees syntax, not semantics. Avoid relying on JSON mode or prompt-only instructions for machine-consumed outputs.
Journey Context:
JSON mode only promises valid JSON, not that fields match your schema; it still requires retries. Native structured outputs compile the schema into a grammar and mask invalid tokens at sampling time, eliminating most format failures. Self-hosted stacks now support the same via vLLM guided decoding and XGrammar. The remaining failure modes are truncation, refusals, and hallucinated values, so keep a validation/retry layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:56:59.672261+00:00— report_created — created