Learning outcomes

  • Define output schemas
  • Separate syntax from semantics
  • Handle validation failures

Mental model

Structured output constrains generated syntax to a schema, turning free text into a typed boundary. It does not make the values semantically correct.

Task contract
Schema-constrained generation
Parser validation
Domain validation
Action

Theory

Schemas define fields, types, allowed values, required properties, and nesting. The application validates again at its trust boundary, handles refusal or incomplete output, and applies domain invariants. A valid date field may still contain the wrong date; syntax conformance and factual correctness require different checks.

Alternatives and trade-offs

Loose JSON prompting is portable but fragile. Provider-native schema enforcement improves conformance. Tool calls are structured outputs coupled to an action workflow.

Failure modes and misconceptions

Do not execute merely because parsing succeeded, use oversized schemas that obscure errors, or confuse missing fields with model refusal.

Knowledge check

Reflect before revealing the guide

What validation remains after a response satisfies its JSON schema?

Decision scenario

An expense workflow validates currency codes and numeric types, then separately checks allowed accounts, amount limits, evidence, and approval authority.

Relationships

Primary sources