[BUG] CrewOutput.json raises bare IndexError when tasks_output is empty (#3185 was never fixed)
Label:
llm-generated— this report was produced with AI assistance (ZCode agent) and human-reviewed. Please apply thellm-generatedlabel.
Problem
CrewOutput.json raises a bare IndexError when tasks_output is empty instead of the guided ValueError the code intends:
@property
def json(self) -> str | None:
if self.tasks_output[-1].output_format != OutputFormat.JSON: # IndexError on []
raise ValueError("No JSON output found in the final task. ...")
tasks_output defaults to an empty list and Crew allows empty task lists, so CrewOutput(raw="...") built outside a kickoff (or deserialized) reproduces it.
History: #3185 reported the same defect; both fix attempts (#3186, #6551) were closed unmerged and the bug is still on main.
Reproduction
from crewai.crews.crew_output import CrewOutput
CrewOutput(raw="no tasks").json # IndexError: list index out of range
Expected behavior
Raise the existing guided ValueError("No JSON output found in the final task. ...") when tasks_output is empty.
A one-line PR with a regression test is attached.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Related fix is up for review in #8741 (CrewOutput.json raises a descriptive ValueError instead of a bare IndexError). Happy to iterate there.