crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] CrewOutput.json raises bare IndexError when tasks_output is empty (#3185 was never fixed)

Open heyseere opened this issue 1 month ago • 2 comments

Label: llm-generated — this report was produced with AI assistance (ZCode agent) and human-reviewed. Please apply the llm-generated label.

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.

heyseere avatar Oct 28 '26 16:10 heyseere

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.

github-actions[bot] avatar Nov 28 '26 12:11 github-actions[bot]

Related fix is up for review in #8741 (CrewOutput.json raises a descriptive ValueError instead of a bare IndexError). Happy to iterate there.

heyseere avatar Nov 30 '26 09:11 heyseere