microsoft/semantic-kernel · error · ContentFilterAIException

{type(agent)} encountered a content error

Error message

{type(agent)} encountered a content error

What it means

Raised as a ContentFilterAIException when the OpenAI Responses create call throws an openai.BadRequestError whose code is "content_filter". This means the Azure OpenAI / OpenAI content-filtering system rejected the prompt or the generated output before/while producing a result. The original BadRequestError is chained as the cause.

Source

Thrown at python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py:622

        tools: Any | None = None,
        response_options: dict | None = None,
        stream: bool = False,
    ) -> Response | AsyncStream[ResponseStreamEvent]:
        try:
            response: Response = await agent.client.responses.create(
                input=cls._prepare_chat_history_for_request(
                    chat_history, store_output_enabled if store_output_enabled is not None else agent.store_enabled
                ),
                instructions=merged_instructions or agent.instructions,
                previous_response_id=previous_response_id,
                store=store_output_enabled,
                tools=tools,  # type: ignore
                stream=stream,
                **response_options,
            )
        except BadRequestError as ex:
            if ex.code == "content_filter":
                raise ContentFilterAIException(
                    f"{type(agent)} encountered a content error",
                    ex,
                ) from ex
            raise AgentExecutionException(
                f"{type(agent)} failed to complete the request",
                ex,
            ) from ex
        except Exception as ex:
            raise AgentExecutionException(
                f"{type(agent)} service failed to complete the request",
                ex,
            ) from ex
        if response is None:
            raise AgentInvokeException("Response is None")
        return response

    @classmethod
    async def _poll_until_completed(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Review the prompt/user input that triggered the filter and remove or rephrase the offending content.
  2. If using Azure OpenAI, adjust the content-filter severity thresholds in the deployment (within your policy), or request a content-filter exception.
  3. Catch ContentFilterAIException specifically and return a user-facing policy message instead of crashing.
  4. Sanitize/validate user input upstream before sending to the agent.

Example fix

# before
try:
    response = await agent.invoke(thread=thread)
except Exception:
    raise
# after - handle content filter specifically
from semantic_kernel.exceptions import ContentFilterAIException
try:
    response = await agent.invoke(thread=thread)
except ContentFilterAIException:
    return "Your request was rejected by the content filter. Please rephrase and try again."
Defensive patterns

Strategy: try-catch

Try / catch

from semantic_kernel.exceptions import ContentFilterAIException
try:
    async for is_final, msg in agent.invoke(thread=thread):
        ...
except ContentFilterAIException:
    # return a safe user-facing message
    return "Your request was blocked by the content filter."

Prevention

When it happens

Trigger: Inside _get_response, agent.client.responses.create raises BadRequestError with ex.code == "content_filter". Triggered by prompts containing content that trips the input filter, or by model output that trips the output filter. Specific to deployments with content filtering enabled (default on Azure OpenAI).

Common situations: Prompt includes sensitive/prohibited content; jailbreak-style or adversarial user inputs; strict Azure content-filter configurations; prompts with PII or violent/explicit language; prompts near policy boundaries that occasionally trip filters depending on model temperature.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/17fff713be52bbb4. Report an issue: GitHub.