Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions litellm/litellm_core_utils/exception_mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ def is_error_str_rate_limit(error_str: str) -> bool:
"""
if not isinstance(error_str, str):
return False

if "429" in error_str or "rate limit" in error_str.lower():
return True

#######################################
# Mistral API returns this error string
#########################################
if "service tier capacity exceeded" in error_str.lower():
return True

return False

@staticmethod
Expand All @@ -68,6 +68,7 @@ def is_error_str_context_window_exceeded(error_str: str) -> bool:
"model's maximum context limit",
"is longer than the model's context length",
"input tokens exceed the configured limit",
"input length and `max_tokens` exceed context limit",
]
for substring in known_exception_substrings:
if substring in _error_str_lowercase:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@
# Tuple format: (error_message, expected_result)
context_window_test_cases = [
# Positive cases (should return True)
("An error occurred: The input exceeds the model's maximum context limit of 8192 tokens.", True),
("Some text before, this model's maximum context length is 4096 tokens. Some text after.", True),
("Validation Error: string too long. expected a string with maximum length 1000.", True),
(
"An error occurred: The input exceeds the model's maximum context limit of 8192 tokens.",
True,
),
(
"Some text before, this model's maximum context length is 4096 tokens. Some text after.",
True,
),
(
"Validation Error: string too long. expected a string with maximum length 1000.",
True,
),
("Your prompt is longer than the model's context length of 2048.", True),
("AWS Bedrock Error: The request payload size has exceed context limit.", True),
("Input tokens exceed the configured limit of 272000 tokens. Your messages resulted in 509178 tokens. Please reduce the length of the messages.", True),

(
"Input tokens exceed the configured limit of 272000 tokens. Your messages resulted in 509178 tokens. Please reduce the length of the messages.",
True,
),
("input length and `max_tokens` exceed context limit", True),
# Test case insensitivity
("ERROR: THIS MODEL'S MAXIMUM CONTEXT LENGTH IS 1024.", True),

# Negative cases (should return False)
("A generic API error occurred.", False),
("Invalid API Key provided.", False),
("Rate limit reached for requests.", False),
("The context is large, but acceptable.", False),
("", False), # Empty string
("", False), # Empty string
]


@pytest.mark.parametrize("error_str, expected", context_window_test_cases)
def test_is_error_str_context_window_exceeded(error_str, expected):
"""
Tests the is_error_str_context_window_exceeded function with various error strings.
"""
assert ExceptionCheckers.is_error_str_context_window_exceeded(error_str) == expected
assert ExceptionCheckers.is_error_str_context_window_exceeded(error_str) == expected
Loading