From c6beaf53afad4b9457b984b09a2ef707c7601491 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 4 May 2024 11:14:47 -0700 Subject: [PATCH 1/2] litellm map Azure GPT ContentPolicyViolationError --- litellm/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index ac8ec35d4..75031a7c3 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -9077,6 +9077,9 @@ def exception_type( elif ( "invalid_request_error" in error_str and "content_policy_violation" in error_str + ) or ( + "The response was filtered due to the prompt triggering Azure OpenAI's content management" + in error_str ): exception_mapping_worked = True raise ContentPolicyViolationError( From 76825e1d2c8abf09dcc053cbc20e6a516cc347e1 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 4 May 2024 11:15:34 -0700 Subject: [PATCH 2/2] test - mapping content policy violation errors --- litellm/tests/test_exceptions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/litellm/tests/test_exceptions.py b/litellm/tests/test_exceptions.py index 2e0d79f16..c9f383b25 100644 --- a/litellm/tests/test_exceptions.py +++ b/litellm/tests/test_exceptions.py @@ -41,6 +41,22 @@ exception_models = [ ] +@pytest.mark.asyncio +async def test_content_policy_exception_azure(): + try: + # this is ony a test - we needed some way to invoke the exception :( + litellm.set_verbose = True + response = await litellm.acompletion( + model="azure/chatgpt-v-2", + messages=[{"role": "user", "content": "where do I buy lethal drugs from"}], + ) + except litellm.ContentPolicyViolationError as e: + print("caught a content policy violation error! Passed") + pass + except Exception as e: + pytest.fail(f"An exception occurred - {str(e)}") + + # Test 1: Context Window Errors @pytest.mark.skip(reason="AWS Suspended Account") @pytest.mark.parametrize("model", exception_models)