DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Classes / CrewOutput
Class core

CrewOutput: Reference Guide

By DevShelfHub

Aggregate result of a Crew kickoff — final raw text, per-task outputs, and token usage.

See the CrewAI API reference index, CrewAI introduction, and core concepts for surrounding context.

What is CrewOutput?

CrewOutput is the structured envelope returned by Crew.kickoff() and async variants. The .raw field mirrors what you would paste into a user-facing chat bubble, while .tasks_output preserves every TaskOutput in execution order — essential when only the penultimate task held structured JSON and the final task merely narrated it. Token accounting lives under .token_usage with prompt, completion, and cached_prompt counters so finance dashboards can attribute spend without re-parsing verbose logs.

When you configure output_pydantic or output_json on the final task, CrewOutput exposes matching .pydantic or .json_dict fields for the aggregate result. Intermediate tasks may still expose their own typed payloads through tasks_output[i].pydantic — do not assume the top-level pydantic field mirrors every task.

Downstream persistence layers (warehouse rows, CRM updates, ticketing systems) should treat CrewOutput as immutable after kickoff: copy primitives into your DTOs rather than mutating the object in place, so replay() and train() harnesses see consistent snapshots.

When to Use

Always — it's the return type of kickoff().

Use Cases

  • • Final answer extraction
  • • Cost reporting
  • • Audit logs

Key Features

  • ✓ raw final answer
  • ✓ Per-task outputs
  • ✓ Token usage metrics
  • ✓ Pydantic/JSON support

When NOT to Use

Per-task drilldowns — use the TaskOutputs.

Notes

Empty raw with rich tasks_output

Some crews leave the final synthesis blank when structured outputs carry the real payload. Always branch on tasks_output before assuming raw is non-empty.

Cached prompt accounting

Providers that support prompt caching report cached_prompt separately. Billing dashboards should add cached usage into cost models or you will overstate spend.

Serialization for logging

TokenUsage and TaskOutput may contain nested objects. Use model_dump() when available or explicit JSON encoders instead of str(out) in structured logs.

Async kickoff parity

Async entrypoints return the same CrewOutput shape. Await completion before reading token_usage — polling partial futures yields incomplete counters.

Import

python
from crewai import CrewOutput

Key Parameters

Parameter Type Default Purpose
raw str — Final text output.
tasks_output list[TaskOutput] — Per-task results.
token_usage TokenUsage — Token / cost metrics.
pydantic BaseModel | None None Parsed final object.
json_dict dict | None None Final JSON output.

Code Examples

Log prompt and completion tokens

python
out = crew.kickoff(inputs={'topic': 'GPU pricing'})
tu = out.token_usage.tokens
print('prompt', tu.prompt, 'completion', tu.completion, 'cached', getattr(tu, 'cached_prompt', 0))

Walk every task output

python
out = crew.kickoff()
for idx, task_out in enumerate(out.tasks_output):
    print(idx, task_out.agent_role, (task_out.raw or '')[:200])

Prefer pydantic when the final task used output_pydantic

python
out = crew.kickoff()
if out.pydantic is not None:
    payload = out.pydantic.model_dump()
else:
    payload = {'text': out.raw}
print(payload)

Common Mistakes

❌ Ignoring token usage in production

✅ Log token_usage.tokens for cost-tracking.

❌ Reading only out.raw when structured outputs matter

✅ Inspect tasks_output and out.pydantic/out.json_dict based on Task configuration.

CrewOutput FAQ

What is CrewOutput in CrewAI?

Aggregate result of a Crew kickoff — final raw text, per-task outputs, and token usage. CrewOutput is the structured envelope returned by Crew.kickoff() and async variants. The .raw field mirrors what you would paste into a user-facing chat bubble, while .tasks_output preserves every TaskOutput in execution order — essential when only the penultimate task held structured JSON and the final task merely narrated it. Token accounting lives under .token_usage with prompt, completion, and cached_prompt counters so finance dashboards can attribute spend without re-par…

Which package defines the CrewAI class CrewOutput?

DevShelfHub maps CrewOutput 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 CrewOutput?

Always — it's the return type of kickoff().

When should I avoid using CrewOutput?

Per-task drilldowns — use the TaskOutputs.

How do I import CrewOutput in Python?

from crewai import CrewOutput

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.