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

Abierto Apto para principiantes
#9,898 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Empieza con CrewOutput.json en crewai/crews/crew_output.py y compara su selección de tareas con Crew._create_crew_output. La reproducción del issue crea una tarea JSON seguida de una tarea vacía omitida; úsala para comprobar el comportamiento. Se considera terminado cuando result.json devuelve el JSON de la tarea anterior y el comportamiento existente de json_dict is None permanece sin cambios.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
61.2k
Forks
9.2k
Merge medio
1 d 14 h
PR fusionados (30 d)
180

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crewAIInc/crewAI

Todos los issues de crewAIInc/crewAI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.