A parser can accept a response that should never reach your database. That is the part structured-output demos tend to hide.
OpenAI and Anthropic now offer APIs that constrain a model's response to a JSON Schema. This solves a real engineering problem: malformed JSON, missing keys, and values outside an allowed enum can stop breaking the next step in a workflow. But a response can satisfy every structural rule and still report the wrong customer, amount, date, or action.
That distinction changes how I would test an AI feature. A green JSON.parse() check tells you the response is readable by software. It does not tell you the response is true.
Two different contracts
A schema defines the shape of a response. It can require an integer, restrict a status to a known set, or ensure that an object contains specific fields. OpenAI describes Structured Outputs as adherence to the supplied JSON Schema. Anthropic describes constrained decoding as a way to return schema-compliant responses.
Those are useful guarantees. They are not a guarantee that the model understood the source correctly.
Take an invoice extractor. It returns a valid object with an invoice_total field containing 540.00. The number is a valid decimal and the object passes validation. It could still belong to the previous invoice in the conversation, or the model may have mistaken a subtotal for the amount due. Syntax cannot catch either error.
The application needs a second contract: what the fields mean, how they relate to the source, and which actions are safe to take from them.
The implementation details matter
The provider documentation also shows why the word “guarantee” needs a precise scope. Anthropic notes that some JSON Schema constraints, such as numeric minimums and string length limits, are not supported directly by the API. Its SDK can transform those constraints into descriptions, then validate the returned value against the original schema locally. That post-response validation is a separate step from constraining generation.
OpenAI's guide makes the schema boundary explicit too: the feature addresses required keys and invalid enum values. Those checks do not establish that a value is supported by the input or corresponds to the intended entity.
A system that relies on a provider's constrained decoder alone may therefore enforce less than its application schema appears to say. Read the provider's supported-schema list, then test the actual SDK path. Do not assume that a schema feature written in code is enforced during decoding unless the runtime says so.
What the benchmark tells us
The JSONSchemaBench study evaluates six constrained-decoding frameworks against 9,558 real-world schemas. It measures efficiency, schema coverage, and downstream task quality rather than treating valid JSON as the only outcome. The authors report that constrained decoding can improve generation speed by up to 50% in their experiments and improve downstream task performance by up to 4% on evaluated tasks.
That is a strong case for using structured generation. It is not evidence that every schema is fully supported or that every field is factually correct. The paper's own evaluation separates schema coverage from output quality. Those are different measurements because they answer different questions.
Test the meaning after the shape
I would keep constrained output as the first boundary, then test the values against the application:
- Check arithmetic relationships, such as whether line items reconcile with a total.
- Resolve returned identifiers against the records the user is allowed to access.
- Validate a proposed action against the current state, not just against an enum.
- Preserve an explicit
unknownornot_foundresult when the source does not support a value. - Keep enough source evidence to inspect why an extracted field was produced.
These checks belong in ordinary application code where possible. A model can propose a value; deterministic logic can reject an impossible transition or a total that does not add up. For harder questions, evaluate the complete task on examples that include ambiguous, incomplete, and misleading inputs. Measuring only parse success will miss the failures users care about.
Structured outputs remove a class of brittle formatting errors. The benchmark suggests that they can help with more than formatting, too. Both points matter. The mistake is treating a machine-readable answer as a verified answer.
When I review an AI workflow, I want two separate results: did the response satisfy the output contract, and did it satisfy the task contract? If the system records only the first, it can make incorrect answers easier to automate.