Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/crewai/src/crewai/crews/crew_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def json(self) -> str | None: # type: ignore[override]

None when that output could not be converted to its ``output_json`` model.
"""
if self.tasks_output[-1].output_format != OutputFormat.JSON:
if (
not self.tasks_output
or self.tasks_output[-1].output_format != OutputFormat.JSON
):
raise ValueError(
"No JSON output found in the final task. Please make sure to set the output_json property in the final task in your crew."
)
Expand Down
12 changes: 12 additions & 0 deletions lib/crewai/tests/test_crew_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from crewai.crews.crew_output import CrewOutput


def test_json_raises_value_error_when_tasks_output_is_empty():
"""A CrewOutput built outside a kickoff (empty tasks_output) must raise the
guided ValueError instead of a bare IndexError."""
output = CrewOutput(raw="no tasks")

with pytest.raises(ValueError, match="No JSON output"):
_ = output.json
Loading