High severity HTTP 403 intermediate · Fix: 5-10 min

AzureOpenAIContentFilterError

azure.openai.error.AzureOpenAIContentFilterError

What this error means
Azure OpenAI's content filter blocked the request due to detected policy violations in the input or output content.

Stack trace

traceback
azure.openai.error.AzureOpenAIContentFilterError: The request was blocked by Azure OpenAI content filter due to policy violation.
    at azure.openai._client._send_request (azure/openai/_client.py:123)
    at azure.openai._client.ChatCompletion.create (azure/openai/_client.py:234)
    at app.py:45
QUICK FIX
Sanitize your input prompt to comply with Azure OpenAI content policies and catch AzureOpenAIContentFilterError exceptions to handle blocked requests gracefully.

Why it happens

Azure OpenAI applies a content filter to detect and block requests containing disallowed or sensitive content based on Microsoft's policy. When the input prompt or generated output triggers this filter, the API returns a content filter error with HTTP 403 status.

Detection

Monitor API responses for AzureOpenAIContentFilterError exceptions or HTTP 403 status codes with content filter messages to catch blocked requests before they cause downstream failures.

Causes & fixes

1

Input prompt contains disallowed or sensitive content triggering the Azure content filter.

✓ Fix

Review and sanitize the input prompt to remove or rephrase content that violates Azure OpenAI content policies.

2

Generated output contains content flagged by the Azure content filter.

✓ Fix

Add stricter prompt instructions to avoid generating disallowed content or implement post-processing filters to detect and handle flagged outputs.

3

Using an Azure OpenAI deployment with strict content filtering enabled by default.

✓ Fix

Check your Azure OpenAI deployment settings and consider adjusting content filter sensitivity or using a deployment with relaxed filtering if policy compliant.

Code: broken vs fixed

Broken - triggers the error
python
from azure.openai import OpenAI
import os

client = OpenAI(deployment_id=os.environ['AZURE_DEPLOYMENT_ID'], endpoint=os.environ['AZURE_ENDPOINT'], api_key=os.environ['AZURE_API_KEY'])

response = client.chat.completions.create(
    deployment_id=os.environ['AZURE_DEPLOYMENT_ID'],
    messages=[{"role": "user", "content": "Some disallowed content here"}]
)  # This line triggers AzureOpenAIContentFilterError
Fixed - works correctly
python
from azure.openai import OpenAI, AzureOpenAIContentFilterError
import os

client = OpenAI(deployment_id=os.environ['AZURE_DEPLOYMENT_ID'], endpoint=os.environ['AZURE_ENDPOINT'], api_key=os.environ['AZURE_API_KEY'])

try:
    response = client.chat.completions.create(
        deployment_id=os.environ['AZURE_DEPLOYMENT_ID'],
        messages=[{"role": "user", "content": "Please provide a safe and policy-compliant prompt."}]
    )  # Fixed: sanitized prompt and added error handling
    print(response.choices[0].message.content)
except AzureOpenAIContentFilterError as e:
    print(f"Content filter blocked the request: {e}")
Added input prompt sanitization to comply with Azure content policies and wrapped the API call in a try/except block to catch and handle AzureOpenAIContentFilterError exceptions.

Workaround

Catch AzureOpenAIContentFilterError exceptions and implement fallback logic such as prompting the user to revise input or logging the incident for manual review.

Prevention

Design prompts carefully to avoid disallowed content, validate inputs before sending to Azure OpenAI, and monitor API responses to handle content filter blocks proactively.

Python 3.9+ · azure-ai-openai >=1.0.0 · tested on 1.1.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.