---
title: "Structured output"
url: "/docs/harness/structured_output"
canonical_url: "https://docs.litellm.ai/docs/harness/structured_output"
type: "docs"
last_updated: "2026-10-01"
summary: "Pass a Pydantic model as output=. The runtime does its normal work, and its final answer is validated into result.output."
related:
  - "/docs/harness/permissions"
  - "/docs/harness/api_reference"
---
# Structured output

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


Pass a Pydantic model as `output=`. The runtime does its normal work, and its final answer is validated into `result.output`.

```python
from typing import Literal
from pydantic import BaseModel

class Review(BaseModel):
    verdict: Literal["approve", "request_changes"]
    issues: list[str]

r = litellm.agent(
    Harness.CLAUDE_CODE,
    "Review the staged diff.",
    output=Review,
    permissions="read-only",
    sandbox=box,
    model="litellm_proxy/coder",
)
r.output.verdict  # "request_changes"
```

| Harness | How the schema is enforced |
|---|---|
| `CLAUDE_CODE` | instruction to answer with one JSON object matching the schema, then validated |
| `CODEX` | Codex's native `--output-schema` |
| `OPENCODE` | instruction to answer with one JSON object matching the schema, then validated |
| `DEEPAGENTS` | `create_deep_agent(response_format=Review)` |

If validation fails, the call raises `OutputInvalid`. The exception carries `.raw` with the model's text and `.result` with the rest of the turn, so the work isn't lost.

## Related pages

- [Permissions](https://docs.litellm.ai/docs/harness/permissions.md)
- [API reference](https://docs.litellm.ai/docs/harness/api_reference.md)
