From 5e893ed13e87bc1ff5cfa198bae6faec3ad4af05 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 21 Jun 2024 21:20:49 -0700 Subject: [PATCH] fix(utils.py): Fix anthropic tool calling exception mapping Fixes https://github.com/BerriAI/litellm/issues/4348 --- litellm/tests/test_exceptions.py | 14 +++++++++----- litellm/utils.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index 01e2129732..3d8cb3c2a3 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -724,11 +724,15 @@ def test_anthropic_tool_calling_exception(): "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", + "parameters": {}, }, } ] - litellm.completion( - model="claude-3.5", - messages=[{"role": "user", "content": "Hey, how's it going?"}], - tools=tools, - ) + try: + litellm.completion( + model="claude-3-5-sonnet-20240620", + messages=[{"role": "user", "content": "Hey, how's it going?"}], + tools=tools, + ) + except litellm.BadRequestError: + pass diff --git a/litellm/utils.py b/litellm/utils.py index d08735080e..831ae433cf 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5922,21 +5922,28 @@ def exception_type( if "prompt is too long" in error_str or "prompt: length" in error_str: exception_mapping_worked = True raise ContextWindowExceededError( - message=error_str, + message="AnthropicError - {}".format(error_str), model=model, llm_provider="anthropic", ) if "Invalid API Key" in error_str: exception_mapping_worked = True raise AuthenticationError( - message=error_str, + message="AnthropicError - {}".format(error_str), model=model, llm_provider="anthropic", ) if "content filtering policy" in error_str: exception_mapping_worked = True raise ContentPolicyViolationError( - message=error_str, + message="AnthropicError - {}".format(error_str), + model=model, + llm_provider="anthropic", + ) + if "Client error '400 Bad Request'" in error_str: + exception_mapping_worked = True + raise BadRequestError( + message="AnthropicError - {}".format(error_str), model=model, llm_provider="anthropic", )