fix: handle None response.choices in OpenAICompatible#1654
Open
Christbowel wants to merge 1 commit intoNVIDIA:mainfrom
Open
fix: handle None response.choices in OpenAICompatible#1654Christbowel wants to merge 1 commit intoNVIDIA:mainfrom
Christbowel wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
response.choices can be None when some endpoints (AWS Bedrock, Azure) filter or refuse a response while still returning HTTP 200. The existing check only tested for the absence of the .choices attribute, not for a None value, causing an unhandled TypeError that crashed the entire run. Fixes NVIDIA#1525 Signed-off-by: christbowel <0xdeadbeef@christbowel.com>
Collaborator
|
Thank you. Explanation is illuminating. Taking a look |
jmartin-tech
approved these changes
Apr 3, 2026
Collaborator
jmartin-tech
left a comment
There was a problem hiding this comment.
This looks sound, it would be nice see a test with a mocked response that validates the behavior.
The existing azure mocks here could be expanded.
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.
What this fixes
response.choicescan beNonewhen endpoints such as AWS Bedrock or Azurereturn HTTP 200 with a filtered or refused response. The existing guard only
checked for the absence of the
.choicesattribute viahasattr(), so aNonevalue passed through and caused an unhandledTypeErrorthat crashedthe entire garak run.
One-line fix: extend the condition to also catch
response.choices is None,reusing the existing retry/fallback logic already in place.
Fixes #1525
Verification
choices: null. The fix is a one-line guard on an already-tested code path.python -m pytest tests/generators/ -vpasses.python -m garak --target_type test.Blank --probes dan.Dan_11_0runs cleanly.