The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(llm_translation): expect an empty choices list to convert instead of raising
mateo-berri17ca562b6a5d
diff --git a/tests/llm_translation/test_llm_response_utils/test_convert_dict_to_chat_completion.py b/tests/llm_translation/test_llm_response_utils/test_convert_dict_to_chat_completion.pyindex b6e30ddc711..09d1adba17c 100644--- a/tests/llm_translation/test_llm_response_utils/test_convert_dict_to_chat_completion.py+++ b/tests/llm_translation/test_llm_response_utils/test_convert_dict_to_chat_completion.py@@ -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 == 10def test_convert_to_model_response_object_null_choices_raises_api_error(self):"""choices=None raises APIError."""