From e02328c9f10be6589c3da8ed85756a25fcf3a313 Mon Sep 17 00:00:00 2001 From: sujan100000 Date: Sun, 26 May 2024 19:09:07 +0930 Subject: [PATCH] Improve validate-fallbacks method * No need to check for fallback_params length * Instead of asserting, used if condition and raised valueError * Improved Error message --- litellm/router.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index 529ba0f759..4e7854a76b 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -348,17 +348,13 @@ class Router: def validate_fallbacks(self, fallback_param: Optional[List]): if fallback_param is None: return - if len(fallback_param) > 0: # if set - ## for dictionary in list, check if only 1 key in dict - for _dict in fallback_param: - assert isinstance(_dict, dict), "Item={}, not a dictionary".format( - _dict - ) - assert ( - len(_dict.keys()) == 1 - ), "Only 1 key allows in dictionary. You set={} for dict={}".format( - len(_dict.keys()), _dict - ) + + for fallback_dict in fallback_param: + if not isinstance(fallback_dict, dict): + raise ValueError(f"Item '{fallback_dict}' is not a dictionary.") + if len(fallback_dict) != 1: + raise ValueError( + f"Dictionary '{fallback_dict}' must have exactly one key, but has {len(fallback_dict)} keys.") def routing_strategy_init(self, routing_strategy: str, routing_strategy_args: dict): if routing_strategy == "least-busy":