From c5867698987f0002a76a971595e9baa082aae06d Mon Sep 17 00:00:00 2001 From: dfedoryshchev Date: Sat, 25 Jul 2026 08:24:12 +0100 Subject: [PATCH 1/5] fix(bedrock): guard empty choices in mistral get_outputText --- .../amazon_mistral_transformation.py | 2 +- .../llms/bedrock/chat/test_mistral_config.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index 58dfa17a722..8ad93ccabf8 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -99,7 +99,7 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): A string with the response of the LLM """ - if "choices" in completion_response: + 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: diff --git a/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py b/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py index 42261cb3bb1..b5cb5e92ff5 100644 --- a/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py +++ b/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py @@ -1,6 +1,9 @@ +import pytest + from litellm.llms.bedrock.chat.invoke_transformations.amazon_mistral_transformation import ( AmazonMistralConfig, ) +from litellm.llms.bedrock.common_utils import BedrockError from litellm.types.utils import ModelResponse @@ -30,3 +33,12 @@ def test_mistral_get_outputText(): assert outputText == "Hi!" assert model_response.choices[0].finish_reason == "finish" + + +def test_mistral_get_outputText_empty_choices(): + model_response = ModelResponse() + + with pytest.raises(BedrockError): + AmazonMistralConfig.get_outputText( + completion_response={"choices": []}, model_response=model_response + ) From 92827ab9bcb3e6dffcadf096fe29f41de9de1bcc Mon Sep 17 00:00:00 2001 From: dfedoryshchev Date: Tue, 28 Jul 2026 14:30:13 +0100 Subject: [PATCH 2/5] fix(bedrock): guard empty outputs in mistral get_outputText --- .../amazon_mistral_transformation.py | 2 +- .../llms/bedrock/chat/test_mistral_config.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index 8ad93ccabf8..61546b659a8 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -102,7 +102,7 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): 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: + elif "outputs" in completion_response and len(completion_response["outputs"]) > 0: outputText = completion_response["outputs"][0]["text"] model_response.choices[0].finish_reason = completion_response["outputs"][0]["stop_reason"] else: diff --git a/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py b/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py index b5cb5e92ff5..9deb3a7a5ed 100644 --- a/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py +++ b/tests/test_litellm/llms/bedrock/chat/test_mistral_config.py @@ -42,3 +42,12 @@ def test_mistral_get_outputText_empty_choices(): AmazonMistralConfig.get_outputText( completion_response={"choices": []}, model_response=model_response ) + + +def test_mistral_get_outputText_empty_outputs(): + model_response = ModelResponse() + + with pytest.raises(BedrockError): + AmazonMistralConfig.get_outputText( + completion_response={"outputs": []}, model_response=model_response + ) From dac896d99012b873f519c5f67c22385757eeabf2 Mon Sep 17 00:00:00 2001 From: dfedoryshchev Date: Fri, 23 Oct 2026 21:43:27 +0100 Subject: [PATCH 3/5] fix: check empty choices and outputs by truthiness, not len() --- .../invoke_transformations/amazon_mistral_transformation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index 155d68c0d6a..c418d7401f1 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -100,10 +100,10 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): A string with the response of the LLM """ - if "choices" in completion_response and len(completion_response["choices"]) > 0: + if "choices" in completion_response and completion_response["choices"]: outputText = completion_response["choices"][0]["message"]["content"] model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"] - elif "outputs" in completion_response and len(completion_response["outputs"]) > 0: + elif "outputs" in completion_response and completion_response["outputs"]: outputText = completion_response["outputs"][0]["text"] model_response.choices[0].finish_reason = completion_response["outputs"][0]["stop_reason"] else: From 78d94bf0fc3fd5ef2b70971fa1974d97cf26b308 Mon Sep 17 00:00:00 2001 From: dfedoryshchev Date: Sat, 24 Oct 2026 10:02:01 +0100 Subject: [PATCH 4/5] fix: use dict.get for the empty choices and outputs checks --- .../invoke_transformations/amazon_mistral_transformation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index c418d7401f1..7a3874f97b9 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -100,10 +100,10 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): A string with the response of the LLM """ - if "choices" in completion_response and completion_response["choices"]: + if completion_response.get("choices"): outputText = completion_response["choices"][0]["message"]["content"] model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"] - elif "outputs" in completion_response and completion_response["outputs"]: + elif completion_response.get("outputs"): outputText = completion_response["outputs"][0]["text"] model_response.choices[0].finish_reason = completion_response["outputs"][0]["stop_reason"] else: From 9b8301551e58156fd57cfcc1216c39f212ba57b1 Mon Sep 17 00:00:00 2001 From: dfedoryshchev Date: Sat, 24 Oct 2026 11:48:48 +0100 Subject: [PATCH 5/5] fix: compare empty choices and outputs to an empty list --- .../invoke_transformations/amazon_mistral_transformation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py index 7a3874f97b9..6a2647d82cb 100644 --- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py +++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_mistral_transformation.py @@ -100,10 +100,10 @@ class AmazonMistralConfig(AmazonInvokeConfig, BaseConfig): A string with the response of the LLM """ - if completion_response.get("choices"): + if "choices" in completion_response and completion_response["choices"] != []: outputText = completion_response["choices"][0]["message"]["content"] model_response.choices[0].finish_reason = completion_response["choices"][0]["finish_reason"] - elif completion_response.get("outputs"): + elif "outputs" in completion_response and completion_response["outputs"] != []: outputText = completion_response["outputs"][0]["text"] model_response.choices[0].finish_reason = completion_response["outputs"][0]["stop_reason"] else: