Repository navigation
Description
Description
What happened?
When Azure OpenAI Responses API blocks a prompt, it can return:
{
"code": "content_filter",
"innererror": {
"code": "ContentFiltered"
}
}
agent-framework-openai attempts to convert this into an OpenAIContentFilterException. However, ContentFilterCodes only contains ResponsibleAIPolicyViolation.
Constructing the intended exception therefore raises:
ValueError: 'ContentFiltered' is not a valid ContentFilterCodes
This masks the original content-filter error. Consequently, middleware or application code using:
except OpenAIContentFilterException:
cannot handle the filtered request.
What did you expect to happen?
The framework should raise OpenAIContentFilterException for all Azure content-filter responses it recognizes, including the Responses API ContentFiltered inner code.
Ideally, unknown future inner codes should not cause exception construction itself to fail.
Steps to reproduce
- Create an openai.BadRequestError representing an Azure Responses API content-filter response.
- Construct OpenAIContentFilterException from it.
- Observe that construction raises ValueError instead of producing an OpenAIContentFilterException.
Code Sample
import httpx
from openai import BadRequestError
from agent_framework_openai import OpenAIContentFilterException
response = httpx.Response(
400,
request=httpx.Request(
"POST",
"https://example.openai.azure.com/openai/v1/responses",
),
)
error = BadRequestError(
"Prompt blocked by content filter",
response=response,
body={
"code": "content_filter",
"param": "prompt",
"innererror": {
"code": "ContentFiltered",
},
"content_filters": [
{
"blocked": True,
"source_type": "prompt",
"content_filter_results": {
"self_harm": {
"filtered": True,
"severity": "medium",
}
},
}
],
},
)
# Expected: an OpenAIContentFilterException instance is constructed.
# Actual: ValueError is raised.
OpenAIContentFilterException("Content filtered", error)Error Messages / Stack Traces
Traceback (most recent call last):
File ".../agent_framework_openai/_chat_client.py", line 686, in _handle_request_error
raise OpenAIContentFilterException(
File ".../agent_framework_openai/_exceptions.py", line 84, in __init__
self.content_filter_code = ContentFilterCodes(
File ".../enum.py", line 1171, in __new__
raise ve_exc
ValueError: 'ContentFiltered' is not a valid ContentFilterCodes
The original error being handled was:
openai.BadRequestError: Error code: 400
error.code: content_filter
error.innererror.code: ContentFilteredPackage Versions
agent-framework-core: 1.16.0 agent-framework-foundry: 1.11.0 agent-framework-openai: 1.14.1 openai: 2.54.0
Python Version
Python 3.12.3
Additional Context
The Azure response comes from the Responses API and includes a top-level content_filters array and innererror.code = "ContentFiltered".
The filter itself is functioning correctly. The bug is specifically in translating the Azure error into OpenAIContentFilterException. This prevents the documented middleware pattern from catching the exception and returning a graceful response.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Sep 15, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
The bug reproduces in
python/packages/openai/agent_framework_openai/_exceptions.py::OpenAIContentFilterException.__init__at line 84 when aBadRequestErrorbody containsinnerror.code = "ContentFiltered". Minimal repro: construct that SDK error using an Azure Responses API payload and pass it toOpenAIContentFilterException, as demonstrated bypython/packages/openai/tests/openai/test_exceptions.py.python/packages/openai/tests/openai/test_exceptions.py1.14.11.14.3Shy7777 commentedon Sep 15, 2026
I'd like to work on a focused fix for this. I reproduced the
ContentFilteredfailure on current main and will add support for that code while preserving the existingResponsibleAIPolicyViolationbehavior. I'll also cover unrecognized inner codes so they cannot replace the intended content-filter exception with aValueError, with regression tests for both Responses and Chat Completions, including streaming. I plan to keep this limited to exception translation and leave the response metadata mapping unchanged.