Structured output asks a model to produce data that conforms to a schema, allowing application code to consume fields instead of parsing prose. Schema conformance is necessary but insufficient: the harness must still enforce business rules, authorization, referential integrity, freshness, and safe behavior when output is missing or invalid.
You will define a typed triage decision, validate syntactic and semantic constraints, and design a bounded repair or rejection path.
A schema is a form, not a fact checker. It can require a priority field and restrict its values, but it cannot prove that a ticket really is urgent or that an order belongs to the current tenant.
domain.py:
Then apply rules that a JSON schema cannot express cleanly:
Choose deliberately:
Record the original output securely, validation errors, repair attempt, and final disposition.
Write deterministic tests before calling a model:
Also test extra fields, overlong strings, unknown enum values, empty citations, and cross-tenant source IDs.
Failure injection: Return valid JSON that references another tenant’s document. Schema validation passes. Authorization-aware semantic validation must fail. This demonstrates why “valid structure” is not “safe action.”
Version schemas, store the version with each outcome, use backward-compatible consumers, and measure validation/repair rates. A sudden increase often indicates prompt drift, a model change, or corrupted context.
Add a versioned migration from TriageDecisionV1 to V2 that introduces confidence evidence without breaking replay of old traces. Write compatibility tests.