Skip to content

fix(crews): raise guided ValueError instead of IndexError from CrewOutput.json on empty tasks - #8741

Open
heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/crew-output-json-empty
Open

heyseere wants to merge 1 commit into
crewAIInc:mainfrom
heyseere:fix/crew-output-json-empty

Conversation

@heyseere

@heyseere heyseere commented Oct 28, 2026 •

Copy link
Copy Markdown

Related issue

Fixes #8737

Summary

CrewOutput.json indexed tasks_output[-1] before checking the output format, so a CrewOutput built outside a kickoff (empty tasks_output, the field default) raised a bare IndexError instead of the guided ValueError. This raises the intended ValueError when tasks_output is empty. (#3185 reported the same defect; its two fix attempts were closed unmerged.)

Verification

  • Tests added or updated for the changed behavior
  • Relevant tests and quality checks pass locally

New lib/crewai/tests/test_crew_output.py::test_json_raises_value_error_when_tasks_output_is_empty fails with IndexError on the old code and passes now. ruff check clean on changed files.

Disclosure: this PR was produced with AI assistance (ZCode agent) and human-reviewed — please apply the llm-generated label.

Additional context

None

From ZCode


Note

Low Risk
Narrow guard-clause change to error handling on an edge case; normal kickoff paths with populated tasks_output are unchanged.

Overview
CrewOutput.json now treats an empty tasks_output list (e.g. a CrewOutput constructed outside kickoff) the same as a final task without JSON format: it raises the existing guided ValueError with the “No JSON output found…” message instead of failing with IndexError on tasks_output[-1].

A regression test in test_crew_output.py asserts that accessing .json on CrewOutput(raw="no tasks") raises ValueError, matching the intended developer-facing error.

Reviewed by Cursor Bugbot for commit 4fdc6e0. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 23 commits after the last Strix review (a983321). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: Fixes `CrewOutput.json` so a `CrewOutput` constructed without task outputs (the field default) raises the intended guided `ValueError` instead of an unhandled `IndexError`, by checking `tasks_output` before reading the last element. Adds one unit test covering the empty case.

Review summary

Reviewed the single-line change in lib/crewai/src/crewai/crews/crew_output.py plus the new test. The diff adds an emptiness guard (not self.tasks_output) before indexing tasks_output[-1], converting a bare IndexError into the already-intended guided ValueError on an error path. This is a pure defensive hardening of an exception path: it introduces no new data flow, sink, sink-side sanitizer removal, or authorization/validation change, and the error message is unchanged so nothing new is disclosed. I also checked whether any code relied on the previous IndexError (no except IndexError handlers in the crew/crews modules), so no caller semantics are broken. No security issues found in the changed code.

Review 1 on this PR · a983321 · requested Oct 28 16:07 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

@heyseere
heyseere force-pushed the fix/crew-output-json-empty branch 2 times, most recently from a25ee0b to 78b4aae Compare October 29, 2026 15:42
@heyseere

Copy link
Copy Markdown
Author

While rebasing onto current main, this branch conflicted with #8702, which already converted the non-JSON-format case into the guided ValueError and added the json_dict is None → None refit semantics. I resolved in favor of main's version and kept this PR's remaining contribution: guarding the empty tasks_output case, which still raised a bare IndexError on main (reproducer in #8737).

The diff is now a one-line guard plus a regression test; tests/test_crew_output.py and the a2a/llm suites pass against main@97bbfb64.

@heyseere

Copy link
Copy Markdown
Author

Friendly ping for a review when you have a moment. All bot checks are green and the PR is mergeable; happy to adjust anything.

@heyseere
heyseere force-pushed the fix/crew-output-json-empty branch from 78b4aae to 4fdc6e0 Compare November 1, 2026 09:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant