Structured LLM output
Section titled “Structured LLM output”Use a machine-checkable schema when model output feeds software rather than a human reader.
A small contract can make the downstream boundary explicit:
{ "type": "object", "required": ["decision", "reason"], "properties": { "decision": { "enum": ["approve", "reject"] }, "reason": { "type": "string" } }}Why it helps
Section titled “Why it helps”A schema makes the expected fields, types, and allowed values explicit. It reduces parsing ambiguity and lets the application reject malformed results before they affect state.
Limits
Section titled “Limits”Valid structure does not prove valid meaning. A model can produce a schema-valid value that is unsupported, inconsistent, or wrong.
Practical guidance
Section titled “Practical guidance”Validate output at the application boundary. Keep schemas as small as the task permits. Distinguish required fields from optional fields and use enumerations when the domain is closed.
After structural validation, apply domain validation for identifiers, ranges, permissions, invariants, and references to external facts.
Do not use free-form text parsing when the downstream contract is already structured.