Skip to content

Structured LLM output

Machine-readable LLM responses governed by an explicit contract, and why valid JSON does not establish factual accuracy or permission to act.

Structured LLM output is a model response arranged in a machine-readable format under an explicit contract for its fields, types and permitted values. In quant research, it lets a filing-extraction pipeline receive a revenue field instead of trying to recover a number from free-form commentary. The contract makes downstream handling more predictable; the extracted figure still needs evidence.

JSON is a common format, but “valid JSON” and “valid extraction” answer different questions.

A small extraction contract

Consider a fictional task: extract revenue in millions of the reported currency for one specified company and reporting period. Accept exactly two fields: revenue, a finite nonnegative number, and currency, either "USD" or "EUR". Both are required; extra fields are rejected. The nonnegative rule is a task assumption, not a universal accounting law.

This is a valid JSON response:

{"revenue": 120, "currency": "USD"}
The keys and currency value need double quotes. A numeric string such as "120" is different from the number 120. One JSON Schema expression of the structural contract is:
{ "type": "object", "properties": { "revenue": {"type": "number", "minimum": 0}, "currency": {"type": "string", "enum": ["USD", "EUR"]} }, "required": ["revenue", "currency"], "additionalProperties": false }
The required and additionalProperties keywords matter: declaring properties alone neither requires their presence nor forbids other fields. minimum supplies the inclusive lower bound; enum limits the currency choices.
Strict JSON excludes bare NaN and Infinity. That does not mean every parser or runtime handles all valid numeric magnitudes and decimal precision identically: RFC 8259, §6 explicitly allows implementation limits. A production contract must also choose a numeric representation and reject nonfinite runtime values or overflow before use. The schema above is an illustration, not a promise of arbitrary-precision arithmetic.

Four checks, four different conclusions

CheckQuestionResult for the example
JSON syntaxCan the text be parsed as strict JSON?Yes
Schema and constraintsAre the required fields, types and allowed values satisfied?Yes: 120 is nonnegative and USD is allowed
Factual evidenceDoes the identified filing report this amount, currency, scale and period?Unresolved without checking that filing
AuthorityMay this system store, transmit or act on the result?Determined by access and execution policy
Changing revenue to -1 preserves JSON syntax and numeric type but violates this contract's lower bound. Changing it to "120" preserves syntax but violates its numeric type. Neither failure is proof about what the filing actually says.
Fictional extraction: revenue 120 and currency USD pass JSON syntax and the specified schema. Agreement with the filing is unverified, and permission to act is a separate policy decision. Revenue minus 1 passes syntax but fails the nonnegative constraint.
Fictional extraction: revenue 120 and currency USD pass JSON syntax and the specified schema. Agreement with the filing is unverified, and permission to act is a separate policy decision. Revenue minus 1 passes syntax but fails the nonnegative constraint.
Figure: Passing the first two checks establishes a usable record shape; it leaves evidence and execution authority unresolved.

Even the accepted record could use the wrong company, last year's revenue, or a figure expressed in thousands rather than millions. An extraction process needs the source document, reporting period and location of the supporting passage available for comparison. Requiring a citation field would require citation text; it would not establish that the cited passage supports the number. This is where financial model hallucination remains possible despite perfect formatting.

Likewise, a schema-valid tool request does not grant permission to execute it. LLM agent guardrails apply separate resource permissions, approval policies and execution limits.

How the structure is obtained

There are distinct mechanisms behind similar-looking responses:

  • Prompting asks the model to follow a format. The request alone does not enforce it.
  • Constrained generation restricts what may be generated while decoding. For example, XGrammar, §2.1 describes masking tokens that violate the permitted structure at the current step. The resulting guarantee is relative to the grammar and constraints actually implemented.
  • Parsing and validation inspect the returned response. Parsing checks JSON syntax; schema validation checks the declared contract. Application checks can cover additional requirements, including source agreement. Validation detects a failure; it does not itself repair one.
  • Retries request another response after a failure. They consume time and budget and can fail again. Repeatedly receiving the same plausible number does not corroborate it.
These mechanisms can be combined. A grammar that enforces JSON syntax is weaker than one that also enforces the intended schema. Even schema-aware generation may support only part of a JSON Schema dialect. As a concrete current example, the Claude structured-output documentation, checked on 1 November 2026, lists numerical constraints such as minimum as unsupported by its constrained-generation interface. A downstream validator must still enforce this example's nonnegative rule; support should be checked for the chosen engine and version.

A refusal, interrupted response or exhausted output limit also needs its own outcome. Do not turn an incomplete record into revenue zero or invent a currency to satisfy required fields. Preserve the failure for review or use a bounded retry policy. The same vendor documentation explicitly describes refusals and output-limit truncation as cases where the expected schema may not be returned.

The useful promise is narrow and valuable: an accepted response fits a known interface. Acceptance as financial evidence, and authorization to act on it, require their own checks.

Sources

Last updated
  • large language models
  • structured output
  • json
  • data validation
← Back to the glossaryBack to top ↑