The Research Report
Constrained Decoding: Guarantees Structure, Not Semantics
The Win and the Gap
Major providers now ship constrained decoding (JSON/schema-enforced outputs). It reliably fixes syntax: valid JSON, correct types, required fields. But semantic errors persist—wrong totals, hallucinated IDs, inconsistent computed values.
The Two-Layer Model
- Schema conformance (mechanical): solved by constrained decoding.
- Semantic correctness (logical): requires validation, business rules, cross-field checks, and possibly re-running computations independently.
Practical Pattern
- Always validate model-provided computed fields (recompute, don't trust).
- Add semantic rule checks and reflect/retry loops.
- Use structured outputs for tool calls and persistence.
- Never skip server-side validation because output looked valid.
Takeaway
Constrained decoding is necessary, not sufficient. Pair it with semantic validation to close the last mile of structured generation reliability.