fix(bedrock): guard empty choices in mistral get_outputText

This commit is contained in:
dfedoryshchev 2026-07-25 08:24:12 +01:00
parent b9b27c2beb
commit c586769898
2 changed files with 13 additions and 1 deletions

View file

@ -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:

View file

@ -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
)