fix(bedrock): guard empty choices in mistral get_outputText#34610
Open
dfedoryshchev wants to merge 1 commit into
Open
fix(bedrock): guard empty choices in mistral get_outputText#34610dfedoryshchev wants to merge 1 commit into
dfedoryshchev wants to merge 1 commit into
Conversation
Contributor
Greptile SummaryThis PR prevents empty Bedrock Mistral
Confidence Score: 5/5The PR appears safe to merge The updated condition prevents indexing an empty choices array, preserves handling of nonempty choices and outputs responses, and the regression test directly exercises the corrected failure case
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py | Safely guards access to the first Mistral choice while preserving the existing outputs fallback and error behavior |
| tests/test_litellm/llms/bedrock/chat/test_mistral_config.py | Adds a focused regression test proving that an empty choices array raises the expected BedrockError |
Reviews (1): Last reviewed commit: "fix(bedrock): guard empty choices in mis..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Sanjays2402
reviewed
Jul 25, 2026
| if "choices" in completion_response and len(completion_response["choices"]) > 0: | ||
| outputText = completion_response["choices"][0]["message"]["content"] | ||
| model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"] | ||
| elif "outputs" in completion_response: |
There was a problem hiding this comment.
the outputs branch a few lines down indexes [0] the same way, so {"outputs": []} still raises IndexError instead of BedrockError. worth guarding both while you are here.
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.
AmazonMistralConfig.get_outputTextguardschoicesby key presence only, so a present-but-emptychoices({"choices": []}, which a bedrock mistral/pixtral response can carry for a filtered or empty generation) reachescompletion_response["choices"][0]and raises an uncaughtIndexErrorthat surfaces as a 500.Added a length check so an empty
choicesfalls through to the existingelseand returns a cleanBedrockError(status_code=400)instead. This mirrors the guard the sibling OpenAI-format handler already uses ininvoke_handler.py("choices" in completion_response and len(...) > 0).Regression test feeds
{"choices": []}throughget_outputTextand assertsBedrockError; it raisedIndexErrorbefore this change.