Applied AI

Structured outputs vs free text: making the LLM commit to a schema

Free-text LLM outputs are hard to log, hard to evaluate, and hard to trust. Structured outputs and function calling turn the model into something a backend can actually operate on. A pragmatic look at when to constrain the model, and when to leave it alone.

5 min readBy Gonzalo Patino
free-text responseschemacontractv1structured output"answer": string"sources": array<id>"confidence": number"rationale": string

The first thing that goes wrong with an LLM integration is not accuracy, it is shape. The model returns a paragraph when the code expected a JSON object. It nests fields differently on Tuesday than it did on Monday. Downstream parsers throw. Evaluations become subjective. Structured outputs solve this at the source: instead of asking the model for a helpful response, you ask it to fill in a schema.

What "structured output" actually means

Structured outputs, whether implemented as function calling, JSON schema, or a Pydantic response model, do the same thing: they constrain the model to produce a value that matches a declared shape. Missing fields, wrong types, extra keys, or invalid enums are prevented at generation time, not caught at parse time. When it works, the code that consumes the model output looks like the code that consumes any other API response.

When to reach for structured output

The clearest signal is that the model output feeds into another program. Classification, extraction, routing, ranking, tool selection, form filling. In all of those, downstream code needs a value it can branch on. Structured output is not a nice-to-have there, it is the whole product.

The second signal is evaluation. A schema-constrained output is trivial to evaluate: compare the generated object to a reference object, field by field. Free-text outputs require another model or a human to evaluate, which is slower, more expensive, and less consistent.

When free text is still the right answer

Evaluation becomes field-by-fieldanswercategorysourcesconfidenceq1✓✓✓✓q2✓✓✗✓q3✓✓✓✓q4✗✓✓✓q5✓✓✓✓accuracy90%per field
When outputs are structured, evaluation reduces to a field-by-field comparison against reference answers, cheap enough to run on every prompt change.

Structured output is not free. It costs surface area in the prompt (the schema takes tokens), it can bias the model toward the shape at the cost of accuracy on edge cases, and it makes the system awkward when the output is genuinely a piece of writing. Long-form summaries, explanations, generated documentation, and chat responses are still text.

A useful pattern is to structure the response, but keep one field as free text. An explanation string, a rationale, a summary. The structured fields carry the machine-readable answer; the text field carries the human-readable one.

Design the schema like an API contract

Response schema — treated like an API contractschema v1.2stableanswer: stringrequiredsources: array<chunk_id>requiredmax 5category: enumrequiredbilling | tech | otherconfidence: numberrequired0.0 – 1.0rationale: stringoptionalhuman-readable
A response schema behaves like an API contract: versioned, with required fields, enums, and stability guarantees for downstream code.

A response schema is a contract. Change it carelessly and everything downstream breaks. Version it: name schemas explicitly, keep old versions callable for a deprecation window, and log the schema version alongside every model call. Make required fields required. Use enums instead of free strings whenever the value comes from a fixed set. Cap list lengths. The schema is the safety net for every parser that comes after.

Validate even when the API "guarantees" it

Provider-side JSON mode and structured output APIs are much more reliable than prompting for JSON, but they are not a substitute for validation. Validate every response against your schema at the boundary. When validation fails, log the raw response, the schema version, and the prompt version, and return a controlled error. That log line is what lets you debug the regression when the provider changes model versions.

What structured outputs unlock

  • Type-safe consumption in application code
  • Straightforward automated evaluation against a reference dataset
  • Cheaper A/B testing across prompt or model changes, because the metric is a value comparison
  • Confident retries: the same input either produces the same shape or fails validation
  • Clean logging and analytics on model behavior over time

Free-text output is where LLMs feel magical. Structured output is where they become software. Most production LLM features live in the second category, and the sooner the model is treated like any other typed dependency, the sooner the rest of the system starts to feel normal.

Enjoyed this piece?

Share it with a colleague or on your feed. It helps more than you think.