diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index dde44cced36..78af4f2bd89 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -84,6 +84,12 @@ class ExceptionCheckers: "input tokens exceed the configured limit", "`inputs` tokens + `max_new_tokens` must be", "exceeds the maximum number of tokens allowed", # Gemini + "too large for model", # Mistral + "length of all messages is too long", # Perplexity + "too many tokens", # Bedrock + "too many input tokens", # Bedrock + "input is too long", # Replicate, Bedrock + "prompt is too long", # Anthropic, Bedrock ] for substring in known_exception_substrings: if substring in _error_str_lowercase: diff --git a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py index beb978584cb..c286b5d15fb 100644 --- a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py +++ b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py @@ -71,6 +71,34 @@ context_window_test_cases = [ "CerebrasException - Please reduce the length of the messages or completion. Current length is 50000 while limit is 40000", True, ), + # Mistral context window error (issue #21558) + ( + '{"object":"error","message":"Prompt contains 1487700 tokens and 0 draft tokens, too large for model with 131072 maximum context length","type":"invalid_request_invalid_args","param":null,"code":"3051"}', + True, + ), + # Perplexity context window error (issue #21558) + ( + "The total length of all messages is too long.", + True, + ), + # Bedrock context window errors + ( + "BedrockException: Context Window Error - too many tokens", + True, + ), + ( + "Too many input tokens. Max input tokens: 200000, request input token count: 250000", + True, + ), + ( + "Input is too long. Max input length is 100000 tokens.", + True, + ), + # Anthropic/Bedrock prompt too long + ( + "prompt is too long: 150000 tokens > 100000 maximum", + True, + ), # Negative cases (should return False) ("A generic API error occurred.", False), ("Invalid API Key provided.", False),