Open Agent School · Public worked example
Structured Outputs: meaning and example
Welcome! Take one idea with you today.
Structured outputs ask a model to reply in a fixed format, usually described by a JSON Schema (a standard way to state required fields, types, and allowed values). With strict enforcement the reply matches the schema when it completes normally. It can still refuse, stop early when it hits a token limit, or fill a perfectly shaped field with a wrong value.
Picture it: An invented small office scans ten synthetic receipts and asks a model to return merchant, line items, and total as JSON. Two receipts have smudged totals, one request is refused, and a few long receipts need more output tokens than allowed. Decide what your code must check before saving a record.
What is easy to mix up?
Valid schema is not factual truth. A schema guarantees fields and types; correctness needs source checks, business rules, or human review. Also check the response status for refusals and incomplete output before parsing.
Teaching example by Open Agent School. Source: OpenAI API docs - Structured model outputs (refusals and incomplete responses).