mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 14:37:59 -05:00
When a Task has both output_pydantic and guardrails configured, if the agent produces invalid JSON that fails Pydantic validation during a retry, the system would crash instead of continuing to the next retry attempt. This fix wraps the _export_output call in a try-except block to catch ValidationError and ConverterError exceptions. When these exceptions occur, the pydantic_output and json_output are set to None, allowing the retry loop to continue and the guardrail to check the raw output. Changes: - Import ValidationError from pydantic and ConverterError from converter - Wrap _export_output calls in try-except in _invoke_guardrail_function - Apply same fix to async version _ainvoke_guardrail_function - Add 3 regression tests covering the issue scenario Co-Authored-By: João <joao@crewai.com>