{"record":{"id":"f163d44d8cefbcfe","repo":"microsoft/autogen","slug":"the-content-is-filtered-because-its-potential-risk-f163d4","errorCode":null,"errorMessage":"The content is filtered because its potential risk. Please try another input.","messagePattern":"The content is filtered because its potential risk\\. Please try another input\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":158,"sourceCode":"        }\n    }\n\n    public IMessage PostProcessMessage(IMessage message)\n    {\n        return message switch\n        {\n            IMessage<ChatCompletion> m => PostProcessChatCompletions(m),\n            _ when strictMode is false => message,\n            _ => throw new InvalidOperationException($\"Invalid return message type {message.GetType().Name}\"),\n        };\n    }\n\n    private IMessage PostProcessChatCompletions(IMessage<ChatCompletion> message)\n    {\n        // throw exception if prompt filter results is not null\n        if (message.Content.FinishReason == ChatFinishReason.ContentFilter)\n        {\n            throw new InvalidOperationException(\"The content is filtered because its potential risk. Please try another input.\");\n        }\n\n        // throw exception is there is more than on choice\n        if (message.Content.Content.Count > 1)\n        {\n            throw new InvalidOperationException(\"The content has more than one choice. Please try another input.\");\n        }\n\n        return PostProcessChatResponseMessage(message.Content, message.From);\n    }\n\n    private IMessage PostProcessChatResponseMessage(ChatCompletion chatCompletion, string? from)\n    {\n        // throw exception if prompt filter results is not null\n        if (chatCompletion.FinishReason == ChatFinishReason.ContentFilter)\n        {\n            throw new InvalidOperationException(\"The content is filtered because its potential risk. Please try another input.\");\n        }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs#L140-L176","documentation":"InvalidOperationException thrown in PostProcessChatCompletions when the ChatCompletion's FinishReason is ChatFinishReason.ContentFilter. OpenAI/Azure content moderation blocked the prompt or completion, so the response carries no usable content and the connector refuses to map it to an empty assistant message.","triggerScenarios":"Calling an OpenAIChatAgent (with connector) whose prompt trips the model's content filter; the API call succeeds but finish_reason is 'content_filter', and post-processing throws.","commonSituations":"Strict Azure OpenAI deployment filters; safety red-teaming workloads; prompts referencing policy-sensitive topics; org-level moderation policies on the OpenAI account.","solutions":["Rephrase the prompt / remove policy-triggering content","Adjust the deployment's content filter severity in Azure OpenAI Studio if permissible","Catch this InvalidOperationException around SendAsync and degrade gracefully (moderation message, alternate prompt, or retry)","Log the failing prompts to build a moderation-aware retry strategy"],"exampleFix":"// before\nvar reply = await agent.SendAsync(prompt); // throws when filtered\n\n// after\ntry { var reply = await agent.SendAsync(prompt); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"content is filtered\"))\n{\n    reply = new TextMessage(Role.Assistant, \"I can't help with that request.\", from: agent.Name);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.Contains(\"content is filtered\")) { /* rephrase prompt and retry once, or return a safe fallback message */ }","preventionTips":["Pre-moderate user-generated prompts","Know the deployment's filter settings","Never let a filtered reply crash a long-running agent loop — always guard SendAsync"],"tags":["autogen","dotnet","openai","content-filter","moderation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}