Skip to main content
Structured output ensures that model inference returns data in a predictable format you can parse programmatically. By providing a JSON Schema, you constrain the model to return valid JSON matching your specification.

Prerequisites

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

The output_format_schema field accepts a JSON Schema object that defines your expected response structure:
The model will return:

Handling schema-validation misses

After the model responds, the platform validates the payload against output_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

Use required 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

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