Skip to main content
By default a run returns one block of text when it finishes. When a downstream system has to consume the result, free-form prose is hard to work with — you end up writing brittle parsers. Structured output makes the model return JSON that conforms to a schema you define, so you can deserialize it directly. For the exhaustive reference — streaming, background runs, error handling, and full schema examples — see Output Control.

Structured output

Set response_format to a json_schema with a name and a schema. The response text conforms to the schema unless generation is cut short. The example below builds the schema from a Pydantic model and validates the response against it:
Reinforce the schema in your prompt (“Return the data as a JSON object matching the schema”) to improve adherence.
Avoid asking for links inside the JSON. A model emitting URLs as part of structured output can produce malformed or fabricated links. Pull links from the citations or search_results items in the response output instead.

Next steps

Keep context

Carry state across multiple turns.

Output Control

Streaming, background runs, error handling, and full structured-output examples.