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

# Structured output

> Get JSON that matches a pydantic model or JSON schema from any provider

Pass a pydantic model as `response_format` to get JSON that matches it:

```python theme={null}
from pydantic import BaseModel

import routehub


class RiskReport(BaseModel):
    title: str
    severity: int


response = routehub.completion(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Assess the main risk of a single-region deployment."}],
    response_format=RiskReport,
)
report = RiskReport.model_validate_json(
    response.choices[0].message.content
)
print(report.title, report.severity)
```

## How it works

* A pydantic class becomes a strict `json_schema` response format.
* A dict is sent as given, so you can pass `{"type": "json_object"}` or your own `json_schema` block.
* The JSON arrives as the message content string. Parse it yourself, as above.
* For Claude, RouteHub enforces the schema through a forced tool call, or native structured output on Claude 5.1 and later, and still returns the result as the message content.

The same code works on every provider that supports structured output:

```python theme={null}
for model in ["gpt-5.4-mini", "claude-sonnet-4-6", "gemini/gemini-3-flash-preview"]:
    response = routehub.completion(
        model=model, messages=messages, response_format=RiskReport
    )
    print(model, RiskReport.model_validate_json(response.choices[0].message.content))
```

> [!TIP]
>
> `routehub.supports_response_schema(model)` tells you whether the catalog lists structured-output support for a model. See [Model catalog](https://docs.swarms.world/routehub/model-catalog.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.