From 71007e0f0e80fd2f0a93f175acf5588d3c1d674f Mon Sep 17 00:00:00 2001 From: otiscuilei Date: Wed, 8 Jul 2026 21:16:56 +0800 Subject: [PATCH] fix: return the helpful error for a bare provider name in get_llm_provider Passing a bare provider name (e.g. get_llm_provider('mistral')) hit the elif that assumes a '/' and did model.split('/', 1)[1], raising IndexError that got wrapped into 'GetLLMProvider Exception - list index out of range'. The sibling if above it already guards this with len(model.split('/')) > 1 (added for issue 1351); the elif was missing the same guard. Add it so a bare provider name falls through to the intended 'LLM Provider NOT provided' guidance. --- litellm/litellm_core_utils/get_llm_provider_logic.py | 2 +- .../test_get_llm_provider_logic.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/test_litellm/litellm_core_utils/test_get_llm_provider_logic.py diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.py index 61a73201c43..932930dc6a0 100644 --- a/litellm/litellm_core_utils/get_llm_provider_logic.py +++ b/litellm/litellm_core_utils/get_llm_provider_logic.py @@ -218,7 +218,7 @@ def get_llm_provider( dynamic_api_key=dynamic_api_key, litellm_params=litellm_params, ) - elif model.split("/", 1)[0] in litellm.provider_list: + elif model.split("/", 1)[0] in litellm.provider_list and len(model.split("/")) > 1: custom_llm_provider = model.split("/", 1)[0] model = model.split("/", 1)[1] if api_base is not None and not isinstance(api_base, str): diff --git a/tests/test_litellm/litellm_core_utils/test_get_llm_provider_logic.py b/tests/test_litellm/litellm_core_utils/test_get_llm_provider_logic.py new file mode 100644 index 00000000000..259355d83a4 --- /dev/null +++ b/tests/test_litellm/litellm_core_utils/test_get_llm_provider_logic.py @@ -0,0 +1,12 @@ +import pytest + +import litellm + + +@pytest.mark.parametrize("model", ["mistral", "openai", "anthropic", "groq", "deepseek"]) +def test_get_llm_provider_bare_provider_name_raises_helpful_error(model): + with pytest.raises(litellm.BadRequestError) as exc_info: + litellm.get_llm_provider(model=model) + message = str(exc_info.value) + assert "LLM Provider NOT provided" in message + assert "list index out of range" not in message