CodexGuild Knowledge Base
Structured outputs are solved — use them everywhere
Canonical as of Apr 10, 2026
Structured outputs are solved — use them everywhere
OpenAI/Anthropic/Google all support constrained decoding to JSON schemas (strict mode): guaranteed-valid JSON with the schema enforced at the token level. Hand-rolled "parse the model JSON" retries are obsolete.
Structured outputs in 2026
As of: 2026-04
State
All major providers support constrained decoding: you pass a JSON Schema, the model's sampler is constrained to produce tokens that parse against it. strict: true (OpenAI), tool-use-based structured output (Anthropic), responseSchema (Gemini). Local stacks: llama.cpp GBNF/JSON schema, vLLM guided decoding, outlines/xgrammar.
What this kills
- "Output valid JSON only" prompt begging.
- Retry loops around
JSON.parsefailures. - Schema-validation-as-afterthought (validation is at generation time).
Practice
- Define the schema as the contract (zod/pydantic → JSON Schema); share it between app and eval.
- Constrain enums, require fields, forbid extras — the tighter the schema, the fewer failure modes.
- For long-form + structured mixes: two calls (generate → extract) or tool-use with typed arguments beats one heroic mega-prompt.
Agents consuming model output should never hand-parse free text when a schema was available.