diff --git a/litellm/router_strategy/least_busy.py b/litellm/router_strategy/least_busy.py index 74b142a1d8b..e4487854f3b 100644 --- a/litellm/router_strategy/least_busy.py +++ b/litellm/router_strategy/least_busy.py @@ -215,13 +215,15 @@ class LeastBusyLoggingHandler(CustomLogger): elif v == min_traffic: min_deployment_ids.append(k) - if min_deployment_ids: - chosen_id = random.choice(min_deployment_ids) - for m in healthy_deployments: - if m["model_info"]["id"] == chosen_id: - return m + if not min_deployment_ids: + raise ValueError("No healthy deployments available") - return random.choice(healthy_deployments) + chosen_id = random.choice(min_deployment_ids) + for m in healthy_deployments: + if m["model_info"]["id"] == chosen_id: + return m + + raise ValueError(f"Chosen deployment id {chosen_id!r} not found in healthy_deployments") def get_available_deployments( self, diff --git a/tests/test_litellm/router_strategy/test_least_busy.py b/tests/test_litellm/router_strategy/test_least_busy.py index a1d678e35c9..f434f6a6f77 100644 --- a/tests/test_litellm/router_strategy/test_least_busy.py +++ b/tests/test_litellm/router_strategy/test_least_busy.py @@ -89,7 +89,6 @@ class TestLeastBusyTieBreaking: healthy_deployments=healthy, all_deployments=dict(counts_with_stale), ) - assert chosen["model_info"]["id"] in ("1", "2") assert chosen["model_info"]["id"] == "1"