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

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.

Source

Thrown at dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs:158

        }
    }

    public IMessage PostProcessMessage(IMessage message)
    {
        return message switch
        {
            IMessage<ChatCompletion> m => PostProcessChatCompletions(m),
            _ when strictMode is false => message,
            _ => throw new InvalidOperationException($"Invalid return message type {message.GetType().Name}"),
        };
    }

    private IMessage PostProcessChatCompletions(IMessage<ChatCompletion> message)
    {
        // throw exception if prompt filter results is not null
        if (message.Content.FinishReason == ChatFinishReason.ContentFilter)
        {
            throw new InvalidOperationException("The content is filtered because its potential risk. Please try another input.");
        }

        // throw exception is there is more than on choice
        if (message.Content.Content.Count > 1)
        {
            throw new InvalidOperationException("The content has more than one choice. Please try another input.");
        }

        return PostProcessChatResponseMessage(message.Content, message.From);
    }

    private IMessage PostProcessChatResponseMessage(ChatCompletion chatCompletion, string? from)
    {
        // throw exception if prompt filter results is not null
        if (chatCompletion.FinishReason == ChatFinishReason.ContentFilter)
        {
            throw new InvalidOperationException("The content is filtered because its potential risk. Please try another input.");
        }

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Rephrase the prompt / remove policy-triggering content
  2. Adjust the deployment's content filter severity in Azure OpenAI Studio if permissible
  3. Catch this InvalidOperationException around SendAsync and degrade gracefully (moderation message, alternate prompt, or retry)
  4. Log the failing prompts to build a moderation-aware retry strategy

Example fix

// before
var reply = await agent.SendAsync(prompt); // throws when filtered

// after
try { var reply = await agent.SendAsync(prompt); }
catch (InvalidOperationException ex) when (ex.Message.Contains("content is filtered"))
{
    reply = new TextMessage(Role.Assistant, "I can't help with that request.", from: agent.Name);
}
Defensive patterns

Strategy: retry

Try / catch

catch (InvalidOperationException ex) when (ex.Message.Contains("content is filtered")) { /* rephrase prompt and retry once, or return a safe fallback message */ }

Prevention

When it happens

Trigger: 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.

Common situations: Strict Azure OpenAI deployment filters; safety red-teaming workloads; prompts referencing policy-sensitive topics; org-level moderation policies on the OpenAI account.

Related errors


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