LowCodeStacks™
Sign in

Azure OpenAI content filter error: blocked prompts and cut-off answers

An Azure OpenAI content filter error is a 400, "The response was filtered", for a blocked prompt, or a 200 with a cut answer. Handle both, then tune the guardrail.

AI & agentsFix a problem8 min read

Checked against Microsoft Learn 12 sources · Updated By · drafted with AI help, checked by a personHow we write guides

An Azure OpenAI content filter error usually reads "The response was filtered due to the prompt triggering content management policy." Azure OpenAI models in Microsoft Foundry run behind a content filter, and calls meet it in two shapes that look nothing alike: that error, for a prompt that was blocked, and a normal-looking success whose answer was cut short. Apps that handle only one of them show users blank or truncated replies with no explanation, and sometimes retry a blocked prompt in a loop. This guide covers both shapes, the annotations that explain them, what the default filter does, and how to change it where that's the right call.

Your app sends a prompt. The content filter checks the prompt first. If it blocks the prompt, the call fails with HTTP 400 and the error code content_filter, the same for chat completions and the Responses API; say so, and don't resend it unchanged, because retries can't change the verdict and are billed each time, so rephrasing is the only way forward. If the prompt passes, the model writes the answer and the filter checks that too. If it filters the answer, the call still succeeds with HTTP 200 but the answer was cut: in chat completions finish_reason is content_filter, on the last chunk for that choice when streaming, and in the Responses API a content_filters entry is blocked; don't present it as whole, tell the user the reply was cut and offer to rephrase. If both checks pass, HTTP 200 returns the full answer to show. It costs money either way: a blocked prompt is billed for the prompt, and a cut answer for the prompt and the tokens generated before the cut. Log the category, not the text.
A blocked prompt returns HTTP 400; a filtered answer returns HTTP 200 with the answer cut.

"The response was filtered": the two shapes of a content filter error

The prompt was blocked. The call fails with HTTP 400 and the error code content_filter, for chat completions and for the Responses API alike. The message wording varies a little between APIs and SDKs; this is the Responses API's:

json
{
  "error": {
    "code": "content_filter",
    "message": "The response was filtered due to the prompt triggering content management policy."
  }
}

The answer was filtered. The call succeeds with HTTP 200, because the prompt was fine, but what the model produced tripped the filter:

  • Chat completions, not streaming: the choice has finish_reason: "content_filter" and, as a rule, no content. In rare cases with longer answers, a partial result comes back with that reason.
  • Chat completions, streaming: chunks arrive normally until filtered content is detected; the last chunk for that choice carries finish_reason: "content_filter".
  • The Responses API: the response object has a top-level content_filters array, one entry per result, with blocked, source_type (prompt or completion), the category results and the character offsets. It's a Foundry extension, so the SDKs don't give it a typed property: read it as an extra field. The response's incomplete_details.reason can also be content_filter.

Not every 400 is the filter. Microsoft lists an invalid payload, a prompt over the context length and unsupported parameters as other causes of a 400, so check the code before you decide what to tell the user.

Handle both in code

python
import openai

try:
    response = client.responses.create(model="gpt-5-mini", input=user_text)
except openai.BadRequestError as error:
    if error.code == "content_filter":
        # The prompt was blocked. Say so; don't resend it unchanged.
        show("That request can't be answered here. Please rephrase it.")
    else:
        raise
else:
    filters = (response.model_extra or {}).get("content_filters") or []
    details = response.incomplete_details
    cut = details is not None and details.reason == "content_filter"
    if cut or any(result.get("blocked") for result in filters):
        # The answer was cut. Don't present it as complete.
        show_partial(response.output_text)
    else:
        show(response.output_text)

Three rules behind that code:

  1. Don't retry a blocked prompt as it is. Retries can't change the verdict and are billed each time. Rephrasing, by the user or your code, is the only way forward.
  2. Don't present a filtered answer as whole. Tell the user the reply was cut, and offer to rephrase.
  3. Log the category, not the text. The annotations (below) say which category fired and at what severity; that's what you need to tune the filter later, and it keeps user content out of your logs.

It costs money either way. Microsoft bills for processing, not for success: a 400 from the filter is charged, because the prompt was evaluated, and so is a 200 with content_filter. For streaming, Microsoft spells it out: the 400 is charged for the prompt evaluation, and the 200 for the prompt and the completion tokens generated before the filter stopped it. Requests the service never processed, such as a 401 or a 429, aren't charged.

Read the annotations

With annotations on, every response carries the filter's verdict for the prompt and the completion: for hate, sexual, violence and self-harm, the severity (safe, low, medium or high) and whether it was filtered; for prompt shields and protected material, whether it was detected and filtered; for protected code, a citation and the licence of the public repository it matched. Chat completions return them as prompt_filter_results and content_filter_results; the Responses API puts them in content_filters. If your app shows code, show the citation too.

What the default guardrail does

A Foundry guardrail is a named set of controls, and every model deployment starts on Microsoft's default one, Microsoft.DefaultV2:

RiskChecked onDefault
Hate and fairness, Sexual, Violence, Self-harmPrompts and completionsBlocks at Medium severity and above
User prompt attacks (jailbreak), through Prompt ShieldsPromptsOn
Protected material, text and codeCompletionsOn
Indirect attacks (instructions hidden in documents you pass in)PromptsOff until you turn it on, and only on text you tag as documents

Severity has four levels: safe, low, medium and high. Safe is always annotated and never blocked. The setting that decides what's blocked uses the same three words in opposite senses, so check which portal you're in:

  • New Foundry portal (guardrails): it's a blocking level. Low blocks only high-severity content, the least restrictive. Medium, the default, blocks medium and high. High blocks low, medium and high, the most restrictive.
  • Foundry (classic) portal (content filters): it's a severity threshold. Low filters low, medium and high, the strictest. High filters only high-severity content.

Off for the four harm categories is split by direction: anyone can turn it off for user input (prompts), but turning it off for output (completions), or setting output to annotate only, needs Microsoft's approval for modified guardrails, by application. The text classifiers are trained and tested on English, German, Japanese, Spanish, French, Italian, Portuguese and Chinese; other languages work, with less certainty, so test in yours.

Legitimate medical, historical or educational text that uses difficult words can still be classed Low or higher rather than Safe, so at a strict setting it can be blocked. When a legitimate case is blocked, the fix is in the guardrail, not in longer prompts.

Tune the guardrail, not the prompt

Guardrails are managed in the new Foundry portal, in the Guardrails area of the Build section; you need the Foundry Account Owner role or higher.

  1. Create a guardrail. Step 1 lists the default controls; pick a risk, the intervention points (user input and output for models; agents add tool call and tool response, in preview) and the action: Annotate or Annotate and block for models (agent guardrails, also in preview, offer annotate and block).
  2. To loosen a default category you can't delete (hate, sexual, violence and self-harm on input and output), add the same risk again with the new blocking level and confirm the override. A lower blocking level blocks less.
  3. Step 2 assigns the guardrail to models and agents. An agent's own guardrail replaces its model's entirely, so an agent with none assigned inherits the model's, and one with its own ignores the model's settings.
  4. Name it and create it. It applies at once. Open the guardrail and try it in the playground to see what "Annotate and block" does before production traffic meets it.

For one-off calls, a request can name a different guardrail with the x-policy-id header; it overrides the deployment's for that call, except for image input. A name that doesn't exist returns InvalidContentFilterPolicy.

Two costs to remember. Each intervention point adds roughly 50 to 100 ms to a call, so keep agents on the controls they need. And turning the filter down is a decision about what reaches your users: Microsoft's advice is to choose each category's level from the consequences of getting it wrong, test with content that's representative of your app, and measure again after every change.

Sources

Add LowCodeStacks as a preferred source on Google

Did this fix it?

Get the weekly email

New guides and updates from LowCodeStacks, every Tuesday. One email a week, no more.

From LowCodeStacks, Regina, SK, contact@lowcodestacks.com. You can unsubscribe any time, from the link in every email or in your privacy settings. See the Privacy notice.

Comments

No comments yet. Share what worked for you.

Sign in to comment. Comments show under a display name you choose, never your email.