Skip to content

fix: CrewOutput.json raises IndexError instead of ValueError on empty tasks_output#6551

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

fix: CrewOutput.json raises IndexError instead of ValueError on empty tasks_output#6551
chuenchen309 wants to merge 1 commit into
crewAIInc:mainfrom
chuenchen309:fix/crew-output-json-empty-tasks-output-v2

Conversation

@chuenchen309

Copy link
Copy Markdown

Problem

CrewOutput.json does self.tasks_output[-1].output_format != ... before checking whether the list is empty, so an empty tasks_output (a genuine, reachable state — constructed directly elsewhere in this test suite, e.g. test_crew.py's kickoff_for_each_async mocks) raises a raw IndexError instead of the intended, documented ValueError one line below.

Fix

Guard with not self.tasks_output or ... before indexing.

Testing

  • New file lib/crewai/tests/test_crew_output.py: asserts the empty-tasks_output case raises ValueError (not IndexError), plus a sanity check that a non-empty, JSON-output final task still returns the dumped JSON.
  • Confirmed red→green: reverting only crew_output.py reproduces IndexError: list index out of range; reapplying passes.
  • Full test_crew_output.py + test_crew.py: 133 passed, 1 skipped (unrelated).
  • ruff check and mypy — clean.
  • xref: no open PR touches crew_output.py.

AI-Generated disclosure

Drafted with Claude Code and personally reviewed/tested before submission. Per CONTRIBUTING.md's llm-generated label requirement: as an external contributor I don't have permission to self-apply GitHub labels (confirmed via gh pr edit --add-label, GraphQL permission error) — disclosing here instead; happy to have a maintainer apply the label if needed.

… tasks_output

`CrewOutput.json` does `self.tasks_output[-1].output_format != ...`
before checking whether the list is empty, so an empty tasks_output
(a genuine, reachable state -- constructed directly elsewhere in this
test suite, e.g. test_crew.py's kickoff_for_each_async mocks) raises a
raw IndexError instead of the intended, documented ValueError one line
below.

Fix: guard with `not self.tasks_output or ...` before indexing.

Rebased onto fresh upstream/main (new-day quota reset after
crewAIInc#6534/crewAIInc#6535 filled yesterday's slots).

AI-Generated PR: Yes, drafted with Claude Code and personally
reviewed/tested before submission. Per CONTRIBUTING.md's llm-generated
label requirement: as an external contributor I cannot self-apply
GitHub labels (confirmed via `gh pr edit --add-label`, GraphQL
permission error) -- disclosing here instead; happy to have a
maintainer apply the label if needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: be378798-4b14-44b8-bff6-18b3829e88de

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5d0ec and 4efeeab.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/crews/crew_output.py
  • lib/crewai/tests/test_crew_output.py

📝 Walkthrough

Walkthrough

Changes

CrewOutput JSON handling

Layer / File(s) Summary
JSON output validation and tests
lib/crewai/src/crewai/crews/crew_output.py, lib/crewai/tests/test_crew_output.py
CrewOutput.json checks for empty task outputs before accessing the final task, raises ValueError when no JSON output exists, and returns serialized JSON for a JSON-formatted final task. Tests cover both behaviors.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing IndexError and restoring the intended ValueError for empty tasks_output.
Description check ✅ Passed The description is directly related to the change and explains the bug, fix, and testing performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant