fix: guard against None input in trimAndLoadJson#2620
Open
bongho wants to merge 1 commit intoconfident-ai:mainfrom
Open
fix: guard against None input in trimAndLoadJson#2620bongho wants to merge 1 commit intoconfident-ai:mainfrom
bongho wants to merge 1 commit intoconfident-ai:mainfrom
Conversation
Fixes AttributeError when LLM returns None instead of a string. Added an explicit None check that raises a descriptive ValueError and sets metric.error when a metric is provided, consistent with the existing error handling pattern in this function. Fixes confident-ai#2554
|
@bongho is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Hi team! Just a friendly ping on this PR. Wanted to note that Issue #2554 was previously addressed by PR #2558 (closed by its author due to CI environment issues, not because of the fix itself). This PR picks up where that left off with the same approach — a minimal |
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.
Problem
When the evaluation LLM returns
None(instead of a string),trimAndLoadJsoncrashes with:This happens because the function calls
input_string.find("{")without first checking whetherinput_stringisNone.Related issue: #2554
Solution
input_stringfromstrtoOptional[str]Noneguard at the top of the function that:ValueErrorwith the same message used for other JSON parse errorsmetric.errorwhen a metric is provided (consistent with existing error handling)Changes
Testing
The fix is minimal and follows the existing error-handling pattern already present in the function's
except json.JSONDecodeErrorblock.