Answers a program can read
When a model output feeds code, free prose is fragile to parse. Format constraints tell the model to emit a fixed structure, such as JSON with named fields, so a program can read it without guessing.
Ways to constrain
- Describe the schema in words, listing each field and its type.
- Show a template with the exact shape and placeholders to fill.
- Give an example of a valid filled output to imitate.
- Use enforced decoding where the runtime restricts tokens to only valid continuations.
Why a schema beats prose
A named schema removes ambiguity about field names and nesting, makes outputs comparable across runs, and lets you validate them automatically. Validation catches a malformed answer before it breaks downstream code.
Common failures
Models may add chatter around the structure, invent extra fields, or drop required ones. Asking for only the structure with no preamble, plus a strict validator with a retry, keeps the pipeline robust.
Key idea
Format constraints make the model emit a fixed schema so code can parse it, and pairing a clear schema with validation and retries keeps structured outputs reliable across runs.