> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runflow.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured Output (JSON Mode)

> Get guaranteed JSON responses from any LLM provider

Force LLM responses into valid JSON format. Supports `json_object` (free-form JSON) and `json_schema` (schema-validated JSON).

## Basic JSON Mode

```typescript theme={null}
const agent = new Agent({
  name: 'Data Extractor',
  instructions: 'Extract structured data from text.',
  model: openai('gpt-4o'),
  modelConfig: {
    responseFormat: { type: 'json_object' }
  }
});
```

## Schema-Validated JSON

Force the response to match a specific schema:

```typescript theme={null}
const agent = new Agent({
  name: 'Profile Extractor',
  instructions: 'Extract person profile from text.',
  model: openai('gpt-4o'),
  modelConfig: {
    responseFormat: {
      type: 'json_schema',
      json_schema: {
        type: 'object',
        properties: {
          name: { type: 'string' },
          age: { type: 'integer' },
          email: { type: 'string' },
        },
        required: ['name', 'age', 'email'],
        additionalProperties: false,
      }
    }
  }
});

const result = await agent.process({ message: 'John Smith, 34, john@example.com' });
const profile = JSON.parse(result.message);
// { name: 'John Smith', age: 34, email: 'john@example.com' }
```

## Provider Support

| Provider  | `json_object` | `json_schema`        | How                                   |
| --------- | ------------- | -------------------- | ------------------------------------- |
| OpenAI    | Native        | Native               | `response_format` API parameter       |
| Gemini    | Native        | Native               | `responseMimeType` + `responseSchema` |
| Anthropic | Not supported | Native (Claude 4.5+) | `output_config.format`                |
| Bedrock   | Not supported | Native (Claude 4.5+) | `output_config` in payload            |
| Groq      | Native        | Not supported        | `response_format` (OpenAI-compatible) |
| xAI       | Native        | Native               | `response_format` (OpenAI-compatible) |

<Note>
  When `json_object` is not natively supported (Anthropic, Bedrock), add JSON instructions to your system prompt for best results.
</Note>

## With LLM Standalone

```typescript theme={null}
const extractor = LLM.openai('gpt-4o', {
  responseFormat: { type: 'json_object' }
});

const result = await extractor.generate('List 3 colors with hex codes', {
  system: 'Respond with valid JSON only.'
});
const data = JSON.parse(result.text);
```

## Anthropic Native JSON Schema

Anthropic Claude 4.5+ models support schema-validated JSON via `output_config`:

```typescript theme={null}
const agent = new Agent({
  name: 'Extractor',
  model: anthropic('claude-sonnet-4-6'),
  modelConfig: {
    responseFormat: {
      type: 'json_schema',
      json_schema: {
        type: 'object',
        properties: {
          name: { type: 'string' },
          age: { type: 'integer' },
        },
        required: ['name', 'age'],
        additionalProperties: false,
      }
    }
  }
});
```

<Note>
  Anthropic requires `additionalProperties: false` on all object types in the schema. Models before Claude 4.5 do not support `json_schema`.
</Note>

## Testing in Prompt Studio

Test structured output in the Portal:

1. Open **Prompts** and select a prompt
2. Click the config icon and change **Format** to "JSON Object" or "JSON Schema"
3. Send a message -- the response will be valid JSON

## Next Steps

<CardGroup cols={2}>
  <Card title="Reasoning" icon="brain" href="/advanced/reasoning">
    Enable chain-of-thought thinking
  </Card>

  <Card title="Server-Side Tools" icon="server" href="/advanced/server-tools">
    Provider-native web search and code execution
  </Card>
</CardGroup>
