-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) Improve retry_decorator with blacklist exceptions #4484
Comments
This new exception class |
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
There is an issue over at litellm on this: BerriAI/litellm#6550 IMHO this solution is better than what we currently have, in the meantime. The code with the |
A potential fix has been generated and a draft PR #5333 has been created. Please review the changes. |
What problem or use case are you trying to solve?
In #4482 a specific exception (for Cloudflare) needed to be treated as non-retryable even though its base exception was
APIError
.The latter is part of the list of retriable exceptions.
cc @neubig
Do you have thoughts on the technical implementation?
I asked
llama-3.1-nemotron-70b-instruct
to come up with an improvement (related files:retry_mixin.py
,llm.py
):Q: How could the
retry_decorator
be enhanced to specify a list of exception types, that should NOT be retried, even if the base exception is part of one in theretry_exceptions
list.Example: see
LLM_RETRY_EXCEPTIONS
, whereAPIError
is a generic exception that could contain text in the error message that would qualify to NOT be retried?Answer:
Enhancing
retry_decorator
to Exclude Specific Exception TypesTo achieve this, we'll modify the
retry_decorator
to accept an additional parameter,exclude_exceptions
, which will contain a list of exception types that should not be retried, even if their base exception is inretry_exceptions
.Updated Code
Explanation
exclude_exceptions
toretry_decorator
, defaulting to an empty list._should_retry
that takes an exception as input._should_retry
checks if the exception is an instance of any type inretry_exceptions
but not an instance of any type inexclude_exceptions
.retry
decorator to use_should_retry
as the condition for retrying exceptions.Example Usage
Custom Exception Example (
APIErrorIfContainsText
)In this example,
APIErrorIfContainsText
is a custom exception that checks if theAPIError
response text contains a specific string. If it does, the exception will be excluded from retries.The text was updated successfully, but these errors were encountered: