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) 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(