Forum Discussion
henry_coding101
Jan 24, 2025Copper Contributor
Azure OpenAI Content Filter Result is always content_filter_error
I'm exploring blocklists as a solution for OpenAI not detecting sensitive words (specifically "wrist-cutting" in my local language (Cantonese) (to be fair not even Chinese AIs know the word)
I have created a Blocklist with 1 entry:
- Term: [鎅𰾛𠝹]手
- Type: Regex
It can block inputs with ease:
{
"error": {
"message": "The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766",
"type": null,
"param": "prompt",
"code": "content_filter",
"status": 400,
"innererror": {
"code": "ResponsibleAIPolicyViolation",
"content_filter_result": {
"custom_blocklists": {
"details": [
{
"filtered": true,
"id": "ChineseBlockList"
}
],
"filtered": true
},
"hate": {
"filtered": false,
"severity": "safe"
},
"profanity": {
"filtered": false,
"detected": false
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
}
}
However, it cannot block outputs.
{
"choices": [
{
"content_filter_result": {
"error": {
"code": "content_filter_error",
"message": "The contents are not filtered"
}
},
"content_filter_results": {},
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "𠝹手(也寫作“拍手”)是一種手部動作,通常是將雙手合攏並用力拍打在一起,發出聲音。這個動作常用於表達讚賞、鼓勵或慶祝,像是在演出結束後觀眾的掌聲,或是在某些活動中用來引起注意。𠝹手也可以用於節奏感的表達,像是在音樂中隨著節拍拍手。這個動作在許多文化中都有其獨特的意義和用途。",
"refusal": null,
"role": "assistant"
}
}
],
"created": 1737702254,
"id": "chatcmpl-At81eUTIzDkZPCKznSKr19YMJU1ud",
"model": "gpt-4o-mini-2024-07-18",
"object": "chat.completion",
"prompt_filter_results": [
{
"prompt_index": 0,
"content_filter_results": {
"custom_blocklists": {
"filtered": false
},
"hate": {
"filtered": false,
"severity": "safe"
},
"profanity": {
"filtered": false,
"detected": false
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
],
"system_fingerprint": "fp_5154047bf2",
"usage": {
"completion_tokens": 138,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens": 34,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
},
"total_tokens": 172
}
}
- ItsBhattiBrass Contributor
If the Azure OpenAI Content Filter always returns content_filter_error, it indicates that something is preventing the content moderation system from functioning correctly. Here are some possible causes and solutions:
1. Check Service Configuration
- Ensure that the Azure OpenAI service is properly set up and that the content filtering feature is enabled.
- Verify that the content_filter parameter is configured correctly in your API request.
2. Inspect Input Content
- Extremely long or complex inputs can cause the filter to fail. Try testing with simpler content to see if the issue persists.
- Remove special characters, large JSON objects, or unusual formatting that might interfere with the filter.
3. Validate API Version
- Confirm that you're using a supported API version. Incompatibilities with outdated versions can cause errors. Use the latest API version for optimal functionality.
4. Check API Limits
- Ensure you’re not exceeding Azure OpenAI's rate limits or quota. If your service is throttled, the content filter may fail.
5. Verify Regional Availability
- The content filtering system might have region-specific limitations or disruptions. Ensure you're deploying in a supported region for OpenAI content filtering.
6. Review Logs for Errors
- Check your Azure Monitor Logs or the API response for more detailed error messages. These can provide insight into why the filter failed.
7. Retry or Implement Fallback Handling
- Implement retry logic in your application to handle temporary issues. If a content_filter_error persists, consider adding a fallback message to prevent interruptions in the user experience.
8. Contact Microsoft Support
- If none of the above resolves the issue, the error could be due to a backend issue. Open a support ticket with Microsoft Azure and provide detailed logs and request payloads for investigation.
Let me know if you'd like detailed guidance on any of these steps!
Take this:
- Check Blocklist Regex: Double-check the regular expression (regex) rules in your blocklist to ensure they are properly defined for the output content.
- Expand Blocklist: Consider adding more variations or similar content to the blocklist, ensuring that related expressions are also captured, in case the current regex doesn't catch all variations.
- Review Content Management Policies: Ensure that your content filtering policies at the Azure level appropriately reflect your customization needs. Sometimes your configuration may not align perfectly with Azure's default filtering policies.
- Logging and Diagnostics: Enable detailed logging to capture more information about why the content filter might be failing. This can give more clues about what's being missed.