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

  1. Rephrase or sanitize the input prompt that triggered the filter
  2. Request a content_filter amendment or adjust the deployment's filter severity in Azure OpenAI Studio
  3. Catch InvalidOperationException and branch to a moderation message or fallback flow
  4. 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

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


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/802a24529748c4c8. Report an issue: GitHub.