fix(converter): fall back on invalid JSON-like partial matches#5461
Open
ibrahim1023 wants to merge 2 commits intocrewAIInc:mainfrom
Open
fix(converter): fall back on invalid JSON-like partial matches#5461ibrahim1023 wants to merge 2 commits intocrewAIInc:mainfrom
ibrahim1023 wants to merge 2 commits intocrewAIInc:mainfrom
Conversation
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 issue #5460.
output_pydanticcould fail when the model output contained brace-delimited text that looked like JSON but was actually plain string content, such as a GraphQL schema. In that case, partial JSON extraction matched the{...}block, Pydantic validation failed, and the error was raised instead of falling back to the normal conversion path.This PR fixes that fallback behavior and adds regression coverage for the reported case.
Changes
handle_partial_json(...)Rationale
The existing partial JSON logic is meant to recover valid JSON embedded in a larger response. The bug was that a false-positive match was handled as fatal, even though it should have been treated the same way as any other unsuccessful partial extraction attempt.
With this change, valid partial JSON still parses as before, while non-JSON brace content now falls through to the existing instruction-based converter path.
Testing
./.venv/bin/python -m pytest lib/crewai/tests/utilities/test_converter.py -k "invalid_json_like_partial or partial_json" -qNotes
uv.lockis intentionally not included because it is unrelated to this fixtest_converter.pyfile in this environment still hits an unrelated pre-existing LiteLLM dependency issue