Report #99244
[research] How do I guarantee valid JSON and schema-conformant output from LLMs across providers?
Use provider-native constrained decoding: OpenAI response\_format json\_schema with strict true, Anthropic output\_config.format json\_schema or forced single-tool tool\_choice, and Gemini response\_json\_schema. On local models use vLLM guided\_json or Ollama format with XGrammar or Outlines. Put reasoning fields before answer fields, keep schemas flat, and still validate with Pydantic.
Journey Context:
JSON Mode only guarantees syntax, not schema. Strict structured outputs compile the schema into a finite-state mask at decode time, eliminating the regex and parse failure class. Each provider accepts different schema features: OpenAI requires additionalProperties false on every object and Anthropic rejects recursive schemas, so portability needs an adapter like Instructor or BAML.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:48:59.040797+00:00— report_created — created