Applied AI Engineering

Structured Outputs & Validation

Structured output turns model responses into data your program can consume. The schema is the start; validation, authorization, business rules, and fallback behavior make it production-safe.
  • A schema is an API contract
  • Syntactic validity is not semantic correctness
  • Unknown must be representable
  • Validation belongs outside the model
  • Repair retries need limits
Treat model output as untrusted input
raw = model.extract(document)
parsed = InvoiceSchema.parse(raw)       // shape + type validation
require_user_can_access(user, parsed.accountId)
require(parsed.amount >= 0)
require(evidence_supports(parsed, document))
save(parsed)
The schema gets you parseable data; it does not prove the data is true or allowed.
Validation layers
LayerExample
SyntaxValid JSON
SchemaRequired fields, enums, numeric types
Business ruleAmount cannot be negative
AuthorizationUser may access accountId
EvidenceExtracted value appears in source
SafetyAction is allowed without human approval
Sources
  • OpenAI API DocumentationStructured output; function calling
  • Claude Prompt Engineering and Evaluation DocsPrompt engineering and tool use
  • Made With MLTesting and evaluation