Skip to main content
Structured outputs give agents predictable, validated data. When a Task sets output_pydantic or output_json, PraisonAI fails the task if the model can’t produce a value matching the schema — no silent None.
The user asks for structured data; the agent returns validated Pydantic output for downstream code.

Quick Start

1

Simple Usage

Define a Pydantic model and pass it to output_pydantic:
2

Multi-Agent Task

Use Task with output_pydantic inside an AgentTeam:

How It Works


Failure Handling

Structured tasks fail-closed — success is False and error carries the schema name plus the parse error when the model can’t match your schema.
When structured output was requested but the model returned prose, the completion checker marks the task incomplete and the existing max_retries loop retries the task. See Task Retry Policy.
Pick the option that matches what your downstream code needs:

Native Structured Output

PraisonAI auto-detects models that support native response_format with JSON schema (GPT-4o, Claude 3.5, Gemini 2.0). Unsupported models fall back to prompt injection.

YAML Configuration

Run with praisonai agents.yaml.

Best Practices

Define only the fields you need. Smaller schemas validate faster and reduce model confusion.
Use output_pydantic when you want a typed object; use output_json when you only need serialisable dicts.
Leave native_structured_output unset unless you know your model needs forcing — the SDK picks the cleanest path.
pydantic is guaranteed populated on success. On failure, read task.result.error for the schema name plus validation error, and task.result.raw for the model text that failed.
Soft models may need a couple of retries to hit the schema. Combine output_pydantic with Task(max_retries=2) from Task Retry Policy.

Structured LLM Errors

Handle validation and LLM failures gracefully

Output & Display

Format and present agent responses

Agent Teams

Multi-agent workflows with structured tasks

Tasks

Task configuration and output options

Task Retry Policy

Retry a task with exponential backoff on structured-output failure