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
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)| Layer | Example |
|---|---|
| Syntax | Valid JSON |
| Schema | Required fields, enums, numeric types |
| Business rule | Amount cannot be negative |
| Authorization | User may access accountId |
| Evidence | Extracted value appears in source |
| Safety | Action is allowed without human approval |