From 9edc10a5439c9090818ddf310f5cb0e7f872b7bc Mon Sep 17 00:00:00 2001 From: michelligabriele Date: Mon, 13 Apr 2026 19:47:30 +0200 Subject: [PATCH] fix(router): lazy-import InternalServerError to break cyclic import --- litellm/router_utils/get_retry_from_policy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/router_utils/get_retry_from_policy.py b/litellm/router_utils/get_retry_from_policy.py index 5ec7175c3a9..b8c6de9b625 100644 --- a/litellm/router_utils/get_retry_from_policy.py +++ b/litellm/router_utils/get_retry_from_policy.py @@ -10,7 +10,6 @@ from litellm.exceptions import ( AuthenticationError, BadRequestError, ContentPolicyViolationError, - InternalServerError, RateLimitError, Timeout, ) @@ -31,6 +30,11 @@ def get_num_retries_from_retry_policy( ContentPolicyViolationErrorRetries: Optional[int] = None InternalServerErrorRetries: Optional[int] = None """ + # Lazy import: `InternalServerError` is defined late in `litellm/exceptions.py`, + # after a cyclic import re-enters this module during exceptions.py evaluation. + # A module-level import would be flagged by CodeQL as potentially undefined. + from litellm.exceptions import InternalServerError + # if we can find the exception then in the retry policy -> return the number of retries if (