fix: handle ValidationError from JSON pattern false positives in converter#5576
Open
VANDRANKI wants to merge 1 commit intocrewAIInc:mainfrom
Open
fix: handle ValidationError from JSON pattern false positives in converter#5576VANDRANKI wants to merge 1 commit intocrewAIInc:mainfrom
VANDRANKI wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…erter
The _JSON_PATTERN regex uses a greedy {.*} match (DOTALL) that can
match any curly-brace content, including GraphQL schemas, template
strings, and other non-JSON text. When such a false-positive match
passes json.JSONDecodeError (it looks like valid JSON) but then fails
Pydantic model validation, the ValidationError was re-raised directly,
crashing the task instead of falling through to convert_with_instructions.
Two changes:
- Make the regex non-greedy ({.*?}) to prefer the shortest match.
- Catch ValidationError with pass instead of raise so that false-positive
regex matches fall through to the LLM-based converter, which handles
the output correctly.
Fixes crewAIInc#5460
Co-Authored-By: kalfa <[email protected]>
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.
Fixes #5460.
Bug
_JSON_PATTERNuses a greedy{.*}regex withre.DOTALL, which can match any content that contains curly braces - including GraphQL schemas, template strings, and similar non-JSON text. When such a false-positive match happens to survivejson.JSONDecodeError(because the outer structure looks valid) but then fails Pydantic model validation, theValidationErrorwas re-raised directly, crashing the task.Changes
Regex: greedy to non-greedy -
{.*}becomes{.*?}to prefer the shortest match, reducing the chance of gobbling up large non-JSON blocks.ValidationError:raisetopass- ifmodel_validate_jsonfails schema validation on a regex match, the match was likely a false positive. Falling through toconvert_with_instructionslets the LLM reformat the output correctly instead of crashing.Why this is safe
convert_with_instructionsis the right fallback for any output the regex misidentifies - it re-prompts the LLM to produce the correct schema. This is already the path taken forjson.JSONDecodeError, so treatingValidationErrorthe same way is consistent.