Skip to main content
Structured output lets you define a Pydantic model and have the LLM return data that conforms exactly to that schema. No more parsing free-text responses.

Basic Usage

Define a Pydantic model and pass it as response_format:
The raw JSON is available in response.content. Parse it into your model using YourModel(**json.loads(response.content)).

Complex Schemas

Structured output handles nested models, lists, enums, and optional fields:

Provider Support

When a provider does not support native structured outputs, Definable automatically includes the JSON Schema in the system prompt and instructs the model to respond in the correct format.

Strict Mode

OpenAI’s strict mode ensures the output adheres exactly to the schema. It is enabled by default:
Set strict_output=False if you encounter schema compatibility issues with strict mode.

Using with Agents

Pass output_schema to an agent run to get structured output from the final response:

Async