Skip to content

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

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

fix(tasks): preserve empty task json outputs#5838
pragnyanramtha wants to merge 4 commits 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 JSON output values are now correctly preserved and included.
  • Tests

    • Added test coverage for empty output scenarios.

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: 748cad48-1774-4103-ada3-442ddc3388cb

📥 Commits

Reviewing files that changed from the base of the PR and between a95d267 and 0681d2d.

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

📝 Walkthrough

Walkthrough

This PR updates TaskOutput serialization methods to use explicit is not None checks instead of truthiness checks. The changes ensure empty but present json_dict and pydantic values are included based on existence rather than emptiness, with new tests validating the behavior.

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.

🎯 1 (Trivial) | ⏱️ ~3 minutes

A task output now knows the difference clear,
'tween empty and absent—let truthiness disappear.
None checks in place of a falsy embrace,
Empty dicts now get their rightful space. 🐰

🚥 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 describes the main change: fixing task output handling to preserve empty JSON outputs instead of falling back to raw text.
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.

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