fix(flow,task): handle pydantic outputs in guardrail retries and checkpoint serialization#5545
Open
ibrahim1023 wants to merge 1 commit intocrewAIInc:mainfrom
Open
Conversation
…kpoint serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5544 by addressing two related issues when using Pydantic outputs in flows/tasks:
TaskOutputwith a non-stringrawvalue when the model returned aBaseModel.PydanticSerializationErrorwheninitial_statewas assigned as a model class on flow subclasses.What Changed
TaskOutputconstruction inlib/crewai/src/crewai/task.pyso initial execution and guardrail retry paths use the same output-shaping logic.raw/pydanticsemantics for structured outputs.Flow.initial_stateremains excluded from serialized flow entities and preserved inherited field metadata when flow subclasses override parent fields inFlowMeta(lib/crewai/src/crewai/flow/flow.py).test_guardrail_retry_preserves_pydantic_output(lib/crewai/tests/test_task.py)test_ainvoke_guardrail_retry_preserves_pydantic_output(lib/crewai/tests/task/test_async_task.py)test_flow_checkpoint_handles_nested_pydantic_models(lib/crewai/tests/test_checkpoint.py)Why
Validation
Passed targeted suites for the touched behavior:
uv run pytest lib/crewai/tests/test_checkpoint.py -quv run pytest lib/crewai/tests/test_task.py -q -k 'guardrail or output_pydantic'uv run pytest lib/crewai/tests/task/test_async_task.py -q -k 'guardrail'Also confirmed new regression tests pass individually after formatting.
Notes
a2a, provider SDK extras,qdrant,oxylabs) and interactive tool prompts in some tool tests.