diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index fb390bb488..8d05996090 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -414,6 +414,35 @@ def test_completion_mistral_exception(): # test_completion_mistral_exception() +def test_completion_bedrock_invalid_role_exception(): + """ + Test if litellm raises a BadRequestError for an invalid role on Bedrock + """ + try: + litellm.set_verbose = True + response = completion( + model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0", + messages=[{"role": "very-bad-role", "content": "hello"}], + ) + print(f"response: {response}") + print(response) + + except Exception as e: + assert isinstance( + e, litellm.BadRequestError + ), "Expected BadRequestError but got {}".format(type(e)) + print("str(e) = {}".format(str(e))) + + # This is important - We we previously returning a poorly formatted error string. Which was + # litellm.BadRequestError: litellm.BadRequestError: Invalid Message passed in {'role': 'very-bad-role', 'content': 'hello'} + + # IMPORTANT ASSERTION + assert ( + (str(e)) + == "litellm.BadRequestError: Invalid Message passed in {'role': 'very-bad-role', 'content': 'hello'}" + ) + + def test_content_policy_exceptionimage_generation_openai(): try: # this is ony a test - we needed some way to invoke the exception :(