[BUG] CrewOutput.json rejects valid JSON when a final conditional task is skipped

Aperta Adatta ai principianti
#9,898 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia da CrewOutput.json in crewai/crews/crew_output.py e confronta la selezione delle attività con Crew._create_crew_output. La riproduzione nell’issue crea un’attività JSON seguita da un’attività vuota ignorata; usala per verificare il comportamento. Il lavoro è completato quando result.json restituisce il JSON dell’attività precedente e il comportamento esistente di json_dict is None rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

When the last ConditionalTask is skipped, it appends an empty TaskOutput in RAW format. Crew._create_crew_output correctly selects the last non-empty task output, so a preceding task's JSON becomes the crew's final json_dict. CrewOutput.json checks tasks_output[-1] instead and raises ValueError even though the returned crew output contains valid JSON.

Steps to Reproduce

Use a crew whose first task produces JSON via output_json, followed by a ConditionalTask whose condition returns False. After Crew.kickoff(), access result.json.

The same state can be reproduced without an LLM:

from crewai.crews.crew_output import CrewOutput
from crewai.tasks.output_format import OutputFormat
from crewai.tasks.task_output import TaskOutput

produced = TaskOutput(
    description="Produce JSON", agent="Writer", raw='{"answer": 42}',
    output_format=OutputFormat.JSON, json_dict={"answer": 42},
)
skipped = TaskOutput(description="Skipped", agent="Reviewer", raw="")
result = CrewOutput(
    raw=produced.raw, json_dict=produced.json_dict,
    tasks_output=[produced, skipped],
)
print(result.json)

On main at 77237aec, the last line raises ValueError: No JSON output found in the final task....

Expected behavior

result.json returns {"answer": 42}, matching the final non-empty task selected for result.raw and result.json_dict.

Screenshots/Code snippets

Crew._create_crew_output uses [t for t in task_outputs if t.raw][-1]; CrewOutput.json currently checks self.tasks_output[-1].output_format.

Environment

  • Operating System: Windows 11
  • Python Version: 3.13.7 (not listed in the issue form's dropdown)
  • crewAI Version: 1.15.45 from this source checkout
  • crewAI Tools Version: not used in this reproduction
  • Virtual Environment: Venv

Evidence

On the patched branch, the focused regression and existing JSON-none control both pass (2 passed), and Ruff passes. A broader VCR-marked test was not run successfully because the Windows event loop could not create a socket in this environment.

Possible Solution

Have CrewOutput.json inspect the last task output with non-empty raw, as Crew._create_crew_output does. The existing json_dict is None behavior can remain unchanged.

Additional context

This differs from #8737 / #8741, which cover an empty tasks_output list, and from #8483, which concerns downstream context after a skipped conditional task.

Lingua principale
Python
Stelle
61.2k
Fork
9.2k
Merge medio
1g 14h
PR unite (30g)
180

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crewAIInc/crewAI

Tutte le issue di crewAIInc/crewAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.