Skip to content
BENIBIX Learn

outputFormat Option

Also known as output_format, Agent SDK structured output, Claude Agent SDK outputFormat

The option that makes the agent end with JSON in a shape you pick.

Think of it like

It is like a form to fill in, not a blank page.

Example

Mia's agent searches the web for recipes. With outputFormat, each result comes back as an object with a title, a time and a list of steps.

Why it matters

Code can use typed data at once. Free text has to be parsed, and parsing breaks.

Definition

outputFormat is the Agent SDK option that asks for the final answer as JSON in a shape you set. In Python it is output_format. You give it a JSON Schema, often made with Zod or Pydantic. The agent can use any tools on the way. The result message then holds the checked data. If no valid answer comes after retries, the run ends with an error.

Example code

typescript
outputFormat: {
  type: "json_schema",
  schema: { type: "object", properties: { title: { type: "string" } } },
}
Ask for an object with a title field.

Common mistake

Reading the result text field. The checked data sits in its own field, called structured_output.

Key takeaways

  1. 1
    Your JSON shape. A schema.
  2. 2
    Tools still allowed. On the way.
  3. 3
    Read structured_output. On success.