diff --git a/src/crewai/task.py b/src/crewai/task.py index 43b9c26c2..273fdfefa 100644 --- a/src/crewai/task.py +++ b/src/crewai/task.py @@ -221,6 +221,16 @@ class Task(BaseModel): if self.output_pydantic or self.output_json: model = self.output_pydantic or self.output_json + + # try to convert task_output directly to pydantic/json + try: + exported_result = model.model_validate_json(result) + if self.output_json: + return exported_result.model_dump() + return exported_result + except Exception: + pass + llm = self.agent.function_calling_llm or self.agent.llm if not self._is_gpt(llm):