test(llm_translation): expect an empty choices list to convert instead of raising

This commit is contained in:
mateo-berri 2026-09-09 13:01:11 -07:00
parent 35def27e7b
commit 17ca562b6a

View file

@ -1623,15 +1623,11 @@ class TestMissingChoicesGuard:
assert "no 'choices'" in exc_info.value.message
def test_convert_to_model_response_object_empty_choices_raises_api_error(self):
"""Empty choices list raises APIError, same as missing/null choices.
def test_convert_to_model_response_object_empty_choices_returns_empty_list(self):
"""An empty choices list is a real provider answer, so it converts to choices=[] instead of raising.
Provider-specific repair (e.g. github_copilot synthesizing choices for
Anthropic-native responses) happens before this guard, in the provider
config; the core utility keeps treating empty choices as an error.
See: https://github.com/BerriAI/litellm/issues/40276
"""
from litellm.exceptions import APIError
response_object = {
"id": "msg_123",
"model": "some-model",
@ -1639,13 +1635,14 @@ class TestMissingChoicesGuard:
"usage": {"prompt_tokens": 10, "completion_tokens": 1, "total_tokens": 11},
}
with pytest.raises(APIError) as exc_info:
convert_to_model_response_object(
response_object=response_object,
model_response_object=ModelResponse(),
)
result = convert_to_model_response_object(
response_object=response_object,
model_response_object=ModelResponse(),
)
assert "no 'choices'" in exc_info.value.message
assert isinstance(result, ModelResponse)
assert result.choices == []
assert result.usage.prompt_tokens == 10
def test_convert_to_model_response_object_null_choices_raises_api_error(self):
"""choices=None raises APIError."""