Skip to main content
Structured output lets you define a JSON schema for the model’s response, ensuring you get consistently typed data back. The OpenAI format uses the standard response_format parameter. The Anthropic Messages format has no response_format; instead you achieve the same result with forced tool use — define a tool whose input_schema is your target schema, require it via tool_choice, and read the typed tool_use block from the response.

JSON Schema

Pass a JSON schema via response_format (OpenAI) or a forced tool (Anthropic) to constrain the model’s output:

With Pydantic (Python)

Use Pydantic models to define your schema and parse the response. The same model_json_schema() output works as the OpenAI json_schema or as an Anthropic tool’s input_schema:

With Zod (TypeScript)

Use Zod schemas with zodResponseFormat (OpenAI), or convert the Zod schema to JSON Schema and use it as an Anthropic tool’s input_schema:

JSON Mode

JSON mode is specific to the OpenAI format. For simpler cases where you just need valid JSON without a specific schema, use JSON mode. (The Anthropic Messages format has no JSON mode — use the forced tool-use pattern shown above when you need structured JSON.)
Python
When using JSON mode without a schema, include “respond in JSON” or similar instructions in your prompt. The model needs to know you expect JSON output.