Structured output
JSON Schema: null, missing and empty are different decisions
Design an extraction contract that distinguishes missing fields, null values and empty strings, with a small review matrix you can test.
By AI Output Check editorial · Published
Original worked examples are hypothetical, not measured product results. Sources checked 2026-11-09.
Decide what an absent answer means
An extraction system can return an empty object, a field with null, or a field with an empty string. These are three different payloads. If your application treats all three as “nothing found,” it may hide whether extraction ran, whether the source lacked a value, or whether a blank value was actually present.
Consider a fictional equipment-return form. You want a return date and a reference supplied by the customer. Some forms have no reference. A sensible contract starts with the downstream decision: should the application display “not supplied,” stop for review, or omit the field entirely? Choose that behavior before asking a model to fill the response.
Technical references: JSON Schema object reference · JSON Schema null reference
Write a small contract with an explicit unknown value
For this example, require a reference field but allow either a nonempty string or null. The complete contract is: {"type":"object","properties":{"reference":{"type":["string","null"],"minLength":1}},"required":["reference"],"additionalProperties":false}. It uses keywords supported by Output Contract Inspector.
The required list controls presence. The type union permits the JSON value null as well as strings. The length rule rejects empty strings; it does not reject null because minLength applies to strings. Listing a field under properties alone does not make that field mandatory. Those are separate decisions.
This contract says nothing about whether a reference exists in the source. It only defines an acceptable representation. Add an instruction such as “Use null when the supplied form does not contain a reference; do not invent one,” then test that instruction separately against source documents.
Technical references: JSON Schema object reference · JSON Schema null reference
Test the states deliberately
Paste the contract into the inspector, then test one response at a time. These examples are authored fixtures, not model-performance measurements.
- {} fails because reference is absent.
- {"reference":null} passes: the field exists and its null value is allowed.
- {"reference":""} fails the minimum string length.
- {"reference":"RETURN-042"} passes structurally, even if that reference was invented.
- {"reference":"null"} passes as a nonempty string. The text "null" is not the JSON value null.
- {"reference":null,"explanation":"not on form"} fails because the extra explanation field is not allowed.
A nonempty string is not necessarily useful text
The response {"reference":" "} also passes this contract: three spaces satisfy minLength. A rule that counts characters is not a rule that trims whitespace or checks an identifier format. If whitespace-only values are unacceptable, check them in application code or use a validator with the additional rules you need.
Do not add pattern or format to this inspector expecting it to enforce them. Its documented subset excludes both. An unsupported-schema result is not evidence that the response is bad; it means this particular tool cannot evaluate that contract. Keep the broader application contract and the inspector’s supported demonstration distinct.
Likewise, a description saying “must be a genuine return reference” is documentation rather than a database lookup. A structural pass cannot confirm that the identifier belongs to the customer or that the return date is possible.
When omission is the better design
An optional reference is a valid design when omission has a clear meaning. Remove reference from required while keeping its property schema, and {} becomes acceptable. The choice is not inherently more or less correct than a required nullable field. It depends on the receiving application and any generation API constraints.
Avoid introducing an accidental fourth convention, such as “N/A,” unless it is part of the contract. A nullable field, an omitted field and a special string are different representations that increase testing work when mixed. Provider generation APIs can impose narrower schema rules than JSON Schema itself, so a local pass is not a provider-compatibility check.
Technical references: JSON Schema object reference · JSON Schema null reference
Keep a contract review checklist
Before publishing a change, keep fixtures for absence, null, empty text, whitespace-only text, a plausible but false value, a wrong type and an unexpected property. Record the expected result for each before running the validator.
After structural validation, run a separate check against the source and the business rule. For the fictional return form, that might mean confirming the reference text appears in the document and asking a person to review mismatches. The inspector can help make representation mistakes visible; it cannot supply the missing evidence or decide whether a return should be approved.
Keep these fixtures with the contract so later edits do not silently change the meaning of a missing answer.
Sources and scope
Provider rules and supported features can change. These sources support the technical background; the worked examples and decision checklists are authored for this article.
- JSON Schema object reference
Presence, properties and additionalProperties semantics; opened 9 November 2026.
- JSON Schema null reference
Null is a value, distinct from an absent property; opened 9 November 2026.