Est.

Structured Output Schemas to Reduce Response Token Counts

Tight schemas cut bloat from AI responses and let cheaper models handle extraction work.

· 8 min read
Cover illustration for “Structured Output Schemas to Reduce Response Token Counts”
Prompt Optimization · October 17, 2026 · 8 min read · 1,772 words

Structured output schemas can make responses easier to parse and cut the number of tokens in them. Tight schemas keep out unwanted prose and fields that are not needed, and let cheaper models handle tasks that suit them. Those savings compound when schema design, model routing, and gateway policies work together.

Why response tokens are the most expensive part of most AI workloads

Output tokens cost materially more per unit than input tokens. That makes an unnecessary sentence in a response more expensive than the same sentence in a prompt. In an extraction pipeline that handles many requests, paying for commentary around every result can turn a little waste on each request into a large bill.

Yet most teams track how much they spend in total without tracking output-token volume on its own. That makes it hard to tell how much goes toward useful results and how much goes toward over-generation. A pipeline can return the right data on every call while paying a lot for text that no downstream system needs. Cutting that text reduces the expensive side of the bill without asking the application to do less useful work.

How unconstrained LLM responses inflate output tokens by default

An unconstrained extraction response often looks like a conversation wrapped around data. It may begin with a friendly preamble, put the JSON inside markdown fences, and end with a disclaimer. Hedging and unsolicited explanations add more text around an otherwise small payload. A typical response can carry roughly 150 tokens of conversational preamble, leaving the requested data as only a fraction of the billed output.

This is the default behavior of a text generator built for human-readable dialogue, applied to a machine-readable task. The model supplies the social and explanatory material that might help a person but does nothing for a parser. Prompting it to be brief asks it to suppress that behavior, while schema enforcement can make whole categories of that behavior unavailable.

The amount of padding also varies across models with similar capability. The model a team chooses therefore changes what a response costs, even when the task and the accuracy it needs stay the same.

What constrained decoding actually does to token generation

Native structured output changes which tokens the model is allowed to generate. A finite state machine derived from the schema tracks the current position in the output. At each step, it masks tokens that would violate the allowed structure, then advances as valid tokens are generated. A conversational preamble cannot appear when the only valid next token belongs to the required data structure.

The model still chooses among valid tokens, but the grammar controls the available paths. This is why constrained decoding provides stronger structural reliability than a prompt asking for JSON. It does not generate unwanted text and remove it afterward, once the tokens have already been spent. It prevents that text from being sampled in the first place.

However, the schema determines how much room remains for verbosity inside valid fields. An unrestricted string can still hold a long explanation even when everything around it is valid JSON. Constrained decoding supplies the boundary, but field design decides how tight that boundary is.

The two hidden token costs that schema design controls, namely schema size and JSON verbosity

A schema creates costs on both sides of a request. The definition consumes input tokens when it is sent, and the resulting JSON consumes output tokens for more than the data alone. Braces, quotes, and repeated key names all make the response longer. These costs are easy to miss because provider billing does not label them as schema overhead.

A large definition costs more to send as input before the model gives an answer. On the output side, descriptive keys and layers of structure repeat across responses, with output tokens charged at the more expensive rate. Together, schema size and JSON verbosity can account for a large share of spending in high-volume document-processing pipelines. Both costs can change even when the application needs structured data.

Meaning Typed Prompting research shows that compact, type-annotated prompts can reduce token usage while maintaining or improving output reliability compared with detailed JSON Schema definitions. The research shows that the cost of describing the requested structure deserves scrutiny as much as the response itself.

Schema shape choices that reduce output token counts in practice

Start with field names because every emitted key has a recurring cost. Long descriptive names cost tokens when the schema is defined and again in every response that includes those fields. Short keys reduce that repetition, making field naming a response-cost decision.

When a field has a bounded set of possible answers, an enum prevents the model from turning a label into a sentence. An open string leaves room for explanation even if the application only needs a category. Choosing an enum in that case reduces the space for elaboration while making the allowed values explicit.

Nesting and optional fields also determine how much structure surrounds the payload. A flatter schema generally needs fewer braces, brackets, and other structural tokens than a deeply nested one. Likewise, an unused field still costs tokens when the response includes its key and a null or empty value.

For large schemas, the next choice is whether each request needs all the elements. Neo4j's Text2Cypher research found that dynamic schema pruning based on what was asked reduced prompt length and computational cost across model sizes. The production analogue is schema-selection logic that sends only the relevant subset, reducing input overhead and hallucination risk. Keep reusable schemas defined at module scope rather than rebuilding them per request, so filtering does not become an excuse for needless schema churn.

Where schema enforcement hurts rather than helps, namely reasoning tasks and the quality trade-off

Tight schema enforcement is a strong fit for extraction and classification. Complex reasoning is the important exception because restrictions on generation can reduce answer quality. Tam et al., 2024 documents performance degradation on tasks including mathematics and object shuffling. A shorter response is not a saving worth pursuing if it makes the required result worse.

The useful distinction is between reasoning and reporting the result of reasoning. A pipeline can leave the reasoning phase unconstrained, then extract a structured answer from its conclusion.

Research on focused reasoning supports a separate way to reduce reasoning tokens. It first organizes essential information into a concise, structured input context, then leaves the reasoning phase unconstrained. On arithmetic tasks, this approach cuts the number of generated tokens by a lot while keeping answers as accurate.

How schema compression and model routing multiply the savings from good schema design

A better schema can change which model is economical. When enforcement eliminates parse failures, a smaller model can become reliable enough for an extraction task previously assigned to a larger one. The schema raises the structural reliability floor and can enable the model swap. Routing should therefore be chosen after the schema is designed, with that design in mind.

That does not remove the need to judge answer quality. Route to the least expensive model that meets the task's requirements with the actual schema in place. Compare its output length on that schema too, because models with similar accuracy can differ substantially in verbosity. A generally efficient model is not necessarily the least verbose choice for a particular extraction response.

Compression and prompt caching can further cut the input overhead when the same schema definitions are sent again and again. Combined with shorter responses and a suitable cheaper model, these changes affect more than one part of the request cost. The interaction matters most in repetitive workloads, including document processing, classification at scale, and structured API responses. Small savings recur often enough there to make joint optimization worthwhile.

Why the gateway layer is where schema-driven token policies become enforceable at scale

Good schemas built by individual engineers do not automatically become organization-wide cost discipline. Different teams can use different definitions, models, and API keys for the same task. Without a shared control point, there is no consistent way to apply routing policy or attribute output-token consumption. An AI gateway provides that layer across teams, models, and providers.

The distinction from a traditional API gateway is what it measures. Traditional gateways inspect headers and route by request count, while AI gateways inspect prompt content and track token use by user, team, model, and endpoint. Quotas on request counts alone miss how costs change when schema design makes responses longer or shorter. Token-aware quotas subject output-token consumption to policy.

Tags for user, team, model, and environment make it possible to connect spending changes to the requests responsible without building custom analytics pipelines. Real-time visibility also makes schema decisions measurable beyond a single engineer's tests. A reduction in response length can be assessed where the production cost is incurred.

Automatic fallback routing keeps a pipeline running when its primary provider goes down, with no need to change the application code. However, the fallback must support the same constrained decoding for the schema if token savings are to survive failover. A managed gateway that needs no proxy to deploy or maintain can provide these controls without a dedicated platform team, which matters especially for AI-native startups with limited headcount.

Applying schema-driven token control in a production pipeline, a decision framework

Begin by classifying each pipeline stage according to what it does. Extraction and classification are candidates for tight schemas and smaller models. Reasoning stages call for structured input context or unconstrained generation, with schema enforcement reserved for the result boundary.

For stages that suit enforcement, design the smallest structure that has what they need. Use short keys, bounded enums, flatter shapes, and no unused optional fields, then filter large definitions to the subset the query needs. Keep reusable schemas stable at module scope to preserve grammar-compilation caching. A new schema incurs compilation latency, while reuse avoids that work while the cache entry remains available, although per-token masking overhead still applies.

Next, choose the cheapest model that gives answers of the required quality with that schema. Measure verbosity on the specific task rather than relying on general benchmark token counts. Use output-token quotas for each team and model at the gateway to enforce those choices. Use real-time attribution to spot sudden increases in average output tokens per call, which can signal a schema change or a more verbose fallback.

Finally, treat fallback compatibility as part of the cost policy. The production pipeline needs to keep its output constraints when routing changes. Each decision multiplies the value of the others, turning structured output from a formatting feature into a durable control on AI spend.

Sources

  1. Enhancing Text2Cypher with Schema Filtering
  2. Meaning Typed Prompting: A Technique for Efficient, Reliable Structured Output Generation
  3. Focused Chain-of-Thought: Efficient LLM Reasoning via Structured Input Information
  4. Schema-Key Wording as an Instruction Channel in Structured Generation under Constrained Decoding

More in Prompt Optimization