output_pydantic or output_json, PraisonAI fails the task if the model can’t produce a value matching the schema — no silent None.
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.Native Structured Output
PraisonAI auto-detects models that support nativeresponse_format with JSON schema (GPT-4o, Claude 3.5, Gemini 2.0). Unsupported models fall back to prompt injection.
YAML Configuration
praisonai agents.yaml.
Best Practices
Keep models small and explicit
Keep models small and explicit
Define only the fields you need. Smaller schemas validate faster and reduce model confusion.
Prefer output_pydantic for Python apps
Prefer output_pydantic for Python apps
Use
output_pydantic when you want a typed object; use output_json when you only need serialisable dicts.Let native mode auto-detect
Let native mode auto-detect
Leave
native_structured_output unset unless you know your model needs forcing — the SDK picks the cleanest path.Check task.result.success for structured tasks
Check task.result.success for structured tasks
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.Use max_retries for flaky models
Use max_retries for flaky models
Soft models may need a couple of retries to hit the schema. Combine
output_pydantic with Task(max_retries=2) from Task Retry Policy.Related
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

