{"record":{"id":"17fff713be52bbb4","repo":"microsoft/semantic-kernel","slug":"type-agent-encountered-a-content-error","errorCode":null,"errorMessage":"{type(agent)} encountered a content error","messagePattern":"(.+?) encountered a content error","errorType":"exception","errorClass":"ContentFilterAIException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py","lineNumber":622,"sourceCode":"        tools: Any | None = None,\n        response_options: dict | None = None,\n        stream: bool = False,\n    ) -> Response | AsyncStream[ResponseStreamEvent]:\n        try:\n            response: Response = await agent.client.responses.create(\n                input=cls._prepare_chat_history_for_request(\n                    chat_history, store_output_enabled if store_output_enabled is not None else agent.store_enabled\n                ),\n                instructions=merged_instructions or agent.instructions,\n                previous_response_id=previous_response_id,\n                store=store_output_enabled,\n                tools=tools,  # type: ignore\n                stream=stream,\n                **response_options,\n            )\n        except BadRequestError as ex:\n            if ex.code == \"content_filter\":\n                raise ContentFilterAIException(\n                    f\"{type(agent)} encountered a content error\",\n                    ex,\n                ) from ex\n            raise AgentExecutionException(\n                f\"{type(agent)} failed to complete the request\",\n                ex,\n            ) from ex\n        except Exception as ex:\n            raise AgentExecutionException(\n                f\"{type(agent)} service failed to complete the request\",\n                ex,\n            ) from ex\n        if response is None:\n            raise AgentInvokeException(\"Response is None\")\n        return response\n\n    @classmethod\n    async def _poll_until_completed(","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py#L604-L640","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Review the prompt/user input that triggered the filter and remove or rephrase the offending content.","If using Azure OpenAI, adjust the content-filter severity thresholds in the deployment (within your policy), or request a content-filter exception.","Catch ContentFilterAIException specifically and return a user-facing policy message instead of crashing.","Sanitize/validate user input upstream before sending to the agent."],"exampleFix":"# before\ntry:\n    response = await agent.invoke(thread=thread)\nexcept Exception:\n    raise\n# after - handle content filter specifically\nfrom semantic_kernel.exceptions import ContentFilterAIException\ntry:\n    response = await agent.invoke(thread=thread)\nexcept ContentFilterAIException:\n    return \"Your request was rejected by the content filter. Please rephrase and try again.\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ContentFilterAIException\ntry:\n    async for is_final, msg in agent.invoke(thread=thread):\n        ...\nexcept ContentFilterAIException:\n    # return a safe user-facing message\n    return \"Your request was blocked by the content filter.\"","preventionTips":["Validate/sanitize user input for policy-sensitive content before invoking the agent.","On Azure, align the deployment content-filter thresholds with your use case.","Catch ContentFilterAIException separately so it degrades gracefully."],"tags":["openai-responses","content-filter","azure","policy"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}