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: ContentFiltered
Package 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.
Description
What happened?
When Azure OpenAI Responses API blocks a prompt, it can return:
agent-framework-openai attempts to convert this into an OpenAIContentFilterException. However, ContentFilterCodes only contains ResponsibleAIPolicyViolation.
Constructing the intended exception therefore raises:
This masks the original content-filter error. Consequently, middleware or application code using:
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
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
Package 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.