Prerequisites
- Familiarity with Running Model Inference
- Basic understanding of JSON Schema
Why structured output matters
Without structured output, LLM responses are free-form text that requires parsing and error handling. With structured output:Defining a schema
Theoutput_format_schema field accepts a JSON Schema object that defines your expected response structure:
Handling schema-validation misses
After the model responds, the platform validates the payload againstoutput_format_schema. If validation fails, the job still completes — the
non-conforming payload is preserved on failed_structured_output instead of
structured_output, so downstream steps run and you can decide how to handle it:
structured_output and failed_structured_output are mutually exclusive — at
most one is populated on a completed job. Always check
failed_structured_output before reading structured_output in code paths
where a schema miss is possible.
Common schema patterns
Simple object with required fields
Arrays of items
Nested objects
Enum constraints
Array of typed objects
TypeScript integration
Define TypeScript interfaces that match your schema for type-safe access:Handling optional fields
Userequired array to specify which fields must be present:
Validating responses
While the model is constrained to the schema, you may want additional runtime validation:Best practices
Adding descriptions for clarity
Troubleshooting
Related content
JSON Schema Reference
Supported JSON Schema features
Running Model Inference
Complete inference guide
Model Inference API
API reference with all types
Structured Output Concepts
Why structured output matters

