What is TaskOutput?
TaskOutput is the envelope CrewAI hands you after one Task finishes: the LLM transcript lives in .raw, while structured extraction surfaces as .pydantic or .json_dict depending on whether you configured output_pydantic or output_json on the Task. Agent metadata fields let downstream logging attribute each artifact to a role without scraping prompts.
Most production code touches TaskOutput inside guardrails, task_callback hooks, or custom persistence layers that fan out to warehouses. CrewOutput.tasks_output is just a list of these objects in kickoff order, so understanding TaskOutput is how you build per-step metrics, diff views between revisions, and selective redaction before sending text to users.
When validation fails, guardrails may mutate or replace the payload before the Task is marked complete — read the object after guardrail success, not mid-retry, if you snapshot outputs externally.
When to Use
Callbacks, guardrails, custom serializers, or analytics that need per-task provenance beyond the final CrewOutput.raw string.
Use Cases
- • Structured output access
- • Per-task logging
- • Persistence pipelines
- • Guardrail validation
- • Token attribution by task
Key Features
- ✓ raw / pydantic / json_dict
- ✓ Agent identity fields
- ✓ Stable hook surface for downstream automation
When NOT to Use
When only the consolidated final answer matters and you never branch on intermediate steps — CrewOutput.raw alone is simpler.
Notes
Which field is authoritative
When output_pydantic succeeds, .raw may still contain the model's chattier text. Downstream business logic should prefer .pydantic or .json_dict for machine contracts and reserve .raw for human-readable archives.
Empty structured fields
If you forgot output_pydantic on the Task, .pydantic stays None even when .raw looks like JSON. The fix is always on the Task definition, not string parsing inside guardrails unless you intentionally accept brittle behavior.
PII in .raw
Guardrails see the same text users might log. Pair SecurityConfig redaction with callbacks that strip secrets before writing TaskOutput snapshots to disk or SaaS tickets.
Ordering
tasks_output order follows Crew scheduling, not necessarily the Python list order you typed if async_execution reshuffles completion. Do not infer dependency edges from list index alone.
Import
from crewai import TaskOutput
Key Parameters
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| raw | str | — | Plain LLM text output. |
| pydantic | BaseModel | None | None | Parsed Pydantic object if configured. |
| json_dict | dict | None | None | Parsed JSON if output_json was set. |
| agent_role | str | — | Role of the agent that produced it. |
| agent_name | str | — | Agent name/identifier. |
Code Examples
Prefer Pydantic when configured
def persist(to: TaskOutput) -> None:
if to.pydantic is not None:
store_json(to.pydantic.model_dump())
elif to.json_dict is not None:
store_json(to.json_dict)
else:
store_text(to.raw)
Guardrail inspecting TaskOutput
def has_citations(to: TaskOutput) -> bool:
text = to.raw.lower()
return 'http://' in text or 'https://' in text
Task(description='Research with URLs', agent=r, guardrail=has_citations, guardrail_max_retries=2)
Iterate CrewOutput.tasks_output
result = crew.kickoff()
for step, out in enumerate(result.tasks_output):
print(step, out.agent_role, len(out.raw))
Common Mistakes
❌ Assuming .pydantic is always populated
✅ Set output_pydantic on the Task first.
❌ json.loads on .raw when output_json was not set
✅ Configure output_json or tolerate free-form text.
TaskOutput FAQ
What is TaskOutput in CrewAI?
Result of a single Task — exposes raw text, Pydantic parsed form, JSON dict, and agent metadata. TaskOutput is the envelope CrewAI hands you after one Task finishes: the LLM transcript lives in .raw, while structured extraction surfaces as .pydantic or .json_dict depending on whether you configured output_pydantic or output_json on the Task. Agent metadata fields let downstream logging attribute each artifact to a role without scraping prompts. Most production code touches TaskOutput inside guardrails, task_callback hooks, or custom persistence layers that fan out to wa…
Which package defines the CrewAI class TaskOutput?
DevShelfHub maps TaskOutput to Python module crewai (package path crewai in this reference). Pin your installed crewai version and match imports to the snippet on this page.
When should I use TaskOutput?
Callbacks, guardrails, custom serializers, or analytics that need per-task provenance beyond the final CrewOutput.raw string.
When should I avoid using TaskOutput?
When only the consolidated final answer matters and you never branch on intermediate steps — CrewOutput.raw alone is simpler.
How do I import TaskOutput in Python?
from crewai import TaskOutput
Where can I explore more CrewAI API reference pages?
Open the CrewAI API reference index on DevShelfHub to search 58 classes, 30 methods, and 16 decorators, each with runnable examples, parameters, common mistakes, and cross-links.