Skip to content

fix(tasks): preserve empty task json outputs#5838

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

fix(tasks): preserve empty task json outputs#5838
pragnyanramtha wants to merge 1 commit into
crewAIInc:mainfrom
pragnyanramtha:fix/task-output-empty-json

Conversation

@pragnyanramtha
Copy link
Copy Markdown

@pragnyanramtha pragnyanramtha commented May 17, 2026

Summary

  • preserve an intentionally empty TaskOutput.json_dict when converting task output to a dict
  • render empty JSON task output as {} instead of falling back to raw text
  • add regression coverage for empty JSON task outputs

Validation

  • uv run pytest lib/crewai/tests/test_task.py::test_task_output_str_with_json_dict lib/crewai/tests/test_task.py::test_task_output_str_with_empty_json_dict lib/crewai/tests/test_task.py::test_task_output_to_dict_prefers_empty_json_dict lib/crewai/tests/test_task.py::test_task_output_str_with_pydantic_and_json_dict -q
  • uv run ruff check lib/crewai/src/crewai/tasks/task_output.py lib/crewai/tests/test_task.py

Contributor Note

This PR was authored with an AI coding assistant. The repository requires the llm-generated label for AI-authored contributions, but GitHub rejected applying that label from this fork with AddLabelsToLabelable permission denied.

Summary by CodeRabbit

  • Bug Fixes

    • Empty-but-present JSON outputs are now preserved and included instead of being treated as absent, ensuring empty JSON objects are returned and displayed correctly.
  • Tests

    • Added tests verifying behavior when JSON output is empty, confirming both string and dictionary representations reflect an empty JSON object.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

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: 17bd5c84-3c73-49c9-9eea-8c7ab73ed239

📥 Commits

Reviewing files that changed from the base of the PR and between 308b800 and c48022b.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/tasks/task_output.py
  • lib/crewai/tests/test_task.py

📝 Walkthrough

Walkthrough

TaskOutput.to_dict() and TaskOutput.str now use explicit is not None checks for json_dict and pydantic, so empty-but-present values are treated as present. Tests added assert str(task_output) == "{}" and task_output.to_dict() == {} for empty JSON output.

Changes

TaskOutput empty-value handling

Layer / File(s) Summary
TaskOutput serialization method updates
lib/crewai/src/crewai/tasks/task_output.py
to_dict() and __str__() replace truthiness conditionals with explicit is not None checks for json_dict and pydantic attributes, changing when empty values are included vs. when fallback to raw occurs.
Empty json_dict test coverage
lib/crewai/tests/test_task.py
New tests verify str() returns "{}" and to_dict() returns empty dict when output_format is JSON with empty json_dict, validating the updated serialization logic.

🎯 3 (Moderate) | ⏱️ ~20 minutes

I nibbled at a boolean bite,
Found None hiding in plain sight.
Empty braces now stand proud and true,
Not swallowed by a falsy view.
A rabbit cheers: empty is new! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(tasks): preserve empty task json outputs' directly and specifically summarizes the main change: fixing the handling of empty JSON task outputs in TaskOutput conversion methods.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 17, 2026 04:27
Copilot AI review requested due to automatic review settings May 17, 2026 04:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pragnyanramtha pragnyanramtha force-pushed the fix/task-output-empty-json branch from 82b2be3 to 308b800 Compare May 21, 2026 07:01
@pragnyanramtha pragnyanramtha force-pushed the fix/task-output-empty-json branch from 308b800 to c48022b Compare May 21, 2026 07:36
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.

2 participants