microsoft/autogen · error · InvalidOperationException
The content is filtered because its potential risk. Please t
Error message
The content is filtered because its potential risk. Please try another input.
What it means
Thrown in PostProcessChatCompletions when the first choice's FinishReason equals CompletionsFinishReason.ContentFiltered. Azure OpenAI's content filter flagged either the prompt or the completion as potentially unsafe, so the model returned no usable content. The connector surfaces this as an explicit InvalidOperationException instead of returning an empty assistant message.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs:131
{
return new ToolCallMessageUpdate(currentToolName, functionArgumentsUpdate, from: update.From);
}
else if (update.Content.ToolCallUpdate is StreamingFunctionToolCallUpdate tooCallUpdate && currentToolName is string)
{
return new ToolCallMessageUpdate(tooCallUpdate.Name ?? currentToolName, tooCallUpdate.ArgumentsUpdate, from: update.From);
}
else
{
return null;
}
}
private IMessage PostProcessChatCompletions(IMessage<ChatCompletions> message)
{
// throw exception if prompt filter results is not null
if (message.Content.Choices[0].FinishReason == CompletionsFinishReason.ContentFiltered)
{
throw new InvalidOperationException("The content is filtered because its potential risk. Please try another input.");
}
return PostProcessChatResponseMessage(message.Content.Choices[0].Message, message.From);
}
private IMessage PostProcessChatResponseMessage(ChatResponseMessage chatResponseMessage, string? from)
{
var textContent = chatResponseMessage.Content;
if (chatResponseMessage.FunctionCall is FunctionCall functionCall)
{
return new ToolCallMessage(functionCall.Name, functionCall.Arguments, from)
{
Content = textContent,
};
}
if (chatResponseMessage.ToolCalls.Where(tc => tc is ChatCompletionsFunctionToolCall).Any())
{View on GitHub (pinned to 027ecf0a37)
Solutions
- Rephrase or sanitize the input prompt that triggered the filter
- Request a content_filter amendment or adjust the deployment's filter severity in Azure OpenAI Studio
- Catch InvalidOperationException and branch to a moderation message or fallback flow
- If using group chat, wrap this agent so a filtered reply doesn't kill the whole conversation loop
Example fix
// before
var reply = await agent.SendAsync("<prompt that trips the filter>"); // throws
// after
try
{
var reply = await agent.SendAsync(prompt);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("content is filtered"))
{
// log and continue conversation with a safer prompt
} Defensive patterns
Strategy: retry
Try / catch
catch (InvalidOperationException ex) when (ex.Message.Contains("content is filtered")) { /* sanitize prompt and retry once, or return moderation message */ } Prevention
- Pre-screen prompts with a moderation endpoint for user-generated input
- Know your deployment's filter configuration
- Wrap agent calls so one filtered reply doesn't crash a group chat loop
When it happens
Trigger: Calling an agent backed by OpenAIChatRequestMessageConnector (strictMode true or false) with prompts containing violence, hate, self-harm, sexual, or jailbreak-adjacent content, or when the deployment's content filter is configured at a strict level; the API succeeds but returns finish_reason 'content_filter'.
Common situations: Strict content-filter configurations on an Azure OpenAI deployment; prompt-injection testing; safety-eval workloads that intentionally probe unsafe content; prompts copied from moderation test suites.
Related errors
- The content is filtered because its potential risk. Please t
- Please set AZURE_OPENAI_API_KEY environment variable.
- Please set AZURE_OPENAI_ENDPOINT environment variable.
- Please set environment variable AZURE_OPENAI_API_KEY
- Invalid return message type {message.GetType().Name}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/802a24529748c4c8.
Report an issue: GitHub.