Structured Outputs JSON: Schemas That Let Models Say Unknown
- Authors

- Name
- João Schuller
- E-commerce Analyst & AI Builder
Structured Outputs JSON: Schemas That Let Models Say Unknown
Structured outputs JSON enforcement solved the parse failure problem, and in doing so it created a quieter one. Ask a model with a strict schema to extract material, country_of_origin, and warranty_months from a supplier description that never mentions a warranty, and you will get a valid object with a warranty number in it. The number looks reasonable and passes every type check, and it comes from nowhere.
The failure at issue here is silent fabrication, and schema design is what prevents it. The shape of your schema decides whether the model has an honest way to say "the source doesn't say", and it also influences how much the model reasons before committing to a value. Both are design choices you make before writing a single prompt.
A schema guarantees shape, not truth
OpenAI's Structured Outputs announcement reports 100% schema reliability for gpt-4o-2024-08-06 on their own evals, and the same page states plainly that Structured Outputs "doesn't prevent all kinds of model mistakes." That second sentence is the one worth underlining. Anthropic's structured outputs documentation makes a similar pitch: without it, Claude can produce malformed JSON that breaks your application, and with it the output conforms to your schema.
My read is that the 100% figure gets quoted as if it meant "reliable extraction", when it only means "reliable syntax". Constrained decoding works by restricting which tokens the model may emit at each step so the output can only ever be valid against the schema. If a field is marked required and typed as an integer, the only legal continuation is an integer. The model has no token available that means "I don't know".
Before constrained decoding, a model missing information might have written "N/A" or apologized in prose, which broke your parser and told you something was wrong. Now the parser never breaks, and the evidence of a problem disappears with it. You traded a loud failure for a silent one.
Take a supplier description that reads "Porcelain tile, 60x60 cm, matte finish, rectified edges." Your schema requires country_of_origin as a string and warranty_months as an integer. Nothing in the text supports either. The model will produce something, because the grammar leaves it no other option, and in a catalog of thousands of SKUs those invented values flow straight into your product pages and marketplace feeds.
Give the model an honest way out
The fix is to make absence a legal value. Doing so sounds trivial and almost nobody does it consistently, because required fields feel safer when you are designing the schema.
Here is a schema fragment for the tile example:
{
"type": "object",
"properties": {
"warranty_months": {
"anyOf": [{ "type": "integer" }, { "type": "null" }]
},
"country_of_origin": {
"type": "string",
"enum": ["BR", "CN", "IT", "ES", "other", "not_stated"]
},
"material_evidence": { "type": "string" },
"material": { "type": "string" }
},
"required": ["warranty_months", "country_of_origin", "material_evidence", "material"],
"additionalProperties": false
}
Three techniques are at work. A nullable type lets numeric fields return null instead of a fabricated number. An explicit not_stated enum value gives categorical fields a sanctioned exit. And an evidence field, here material_evidence, asks the model to quote the source text that supports the value. If the quote is empty or doesn't appear in the original description, you have a machine-checkable signal that the extraction is unsupported.
A confidence field is a fourth option, though in my view it is the weakest of the set. Self-reported confidence from a language model tends to be poorly calibrated, so treat it as a routing hint at best. A quoted span is verifiable and a confidence score is not.
The problem is a prompt problem as much as a schema problem. The schema offers the exit, and the instruction has to tell the model when to take it. Something like "use null or not_stated whenever the description does not explicitly state the value; never infer from product type" does real work here. The same logic as negative constraints in prompts applies: the model needs to know the exit is preferred over a plausible guess.
Field order is a reasoning decision
Models generate tokens sequentially, and constrained decoding does not change that. Whatever appears earlier in the output conditions everything after it. A schema that lists the final answer first forces the model to commit before it has produced any supporting text.
Compare two orderings for a classification field:
{ "category": "...", "reasoning": "..." }
versus
{ "reasoning": "...", "category": "..." }
In the first, reasoning is a post-hoc justification of a choice already made. In the second, it functions like a short chain of thought that the final value can draw on. My inference is that this matters most on ambiguous inputs, which are exactly the inputs where you most need accuracy. I have not seen a controlled benchmark I would cite for a specific effect size, so treat the direction as well-motivated and the magnitude as something to measure on your own data. The reasoning behind it is the same one covered in the post on chain-of-thought prompting: intermediate tokens give the model something to condition on.
Practically, the ordering I would use for extraction is: evidence quote first, then reasoning if the case is ambiguous, then the typed value. Putting material_evidence before material in the example above is deliberate, and in a real schema I would reorder it that way. Most SDKs serialize properties in declaration order, but check your provider's behavior, since some schema compilers normalize or reorder keys.
Validation is a separate pass, not a schema feature
Even with nullable fields and evidence quotes, the schema cannot verify that the quote exists in the source. That check lives outside the model.
A minimal validation pass takes the extracted object and the original text, and tests each claim mechanically. Does material_evidence appear as a substring of the source after whitespace normalization? Is warranty_months non-null only when the source contains a digit near the word "warranty" or "garantia"? Does an enum value of BR have a supporting phrase? Failures route to a review queue instead of the catalog.
Running these checks costs almost nothing compared to the alternative. A second model call acting as a verifier works too, but string matching on quoted evidence catches the most common fabrications for almost no cost. OpenAI's own docs suggest validation libraries and retries as a fallback when native enforcement isn't available, and I would extend that logic: keep validation even when it is.
One limitation is worth stating. Quote-checking confirms the model found text, not that it read the text correctly. "Garantia de fábrica" could be quoted accurately and still be mapped to the wrong number of months. Semantic errors survive the substring check, so sample outputs by hand periodically.
From my experience
In my work on product catalog and marketplace integrations, the fields that cause damage are rarely the ones that fail loudly. A missing dimension gets caught because a feed rejects the row. A plausible but unsupported attribute sails through, gets syndicated to marketplaces, and surfaces weeks later as a customer complaint or a return reason. That pattern is why I treat "valid against the schema" as the start of validation, not the end. Anything an LLM extracts into a catalog field gets an evidence trail or a null, and I would rather have a gap I can see than a value I can't trust.
FAQ
Does Structured Outputs eliminate hallucinated values? No. OpenAI states on the launch page that it doesn't prevent all kinds of model mistakes. It guarantees the output matches your schema, which is a statement about structure and not about accuracy.
Should every field be nullable? Only fields where the source may legitimately not contain the answer. Making everything nullable invites the model to skip work it could have done, so reserve nulls for attributes that are genuinely optional in your source material.
Is prompt-only JSON still worth knowing? OpenAI's API docs recommend always using Structured Outputs over JSON mode when possible. Prompt-based formatting remains useful for providers or models without native enforcement, paired with a validation library and retries.
A field that cannot be left empty will eventually be filled with something false, which is why the schema has to offer the model a legal way to say nothing.
E-commerce Analyst & AI Builder
E-commerce Analyst & Product Owner at the largest flooring and tile retailer in Southern Brazil. 5 years in online retail working with Magento, VTEX, GA4, and Claude. Writes about practical AI for professionals who build things.
Read more about João →