Skip to main content

JSON mode

Force the model to return valid JSON by setting response_format:

JSON Schema (strict mode)

Define the exact shape of the response:
The response will always match your schema. No parsing errors.

Which models support structured outputs?

If a model doesn’t support json_schema, use json_object mode and describe the format in your prompt. It works with all models.

With Pydantic (Python)

With TypeScript/Zod