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
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.
"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:
{
"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_filtersarray, one entry per result, withblocked,source_type(promptorcompletion), 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'sincomplete_details.reasoncan also becontent_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
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:
- 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.
- Don't present a filtered answer as whole. Tell the user the reply was cut, and offer to rephrase.
- 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:
| Risk | Checked on | Default |
|---|---|---|
| Hate and fairness, Sexual, Violence, Self-harm | Prompts and completions | Blocks at Medium severity and above |
| User prompt attacks (jailbreak), through Prompt Shields | Prompts | On |
| Protected material, text and code | Completions | On |
| Indirect attacks (instructions hidden in documents you pass in) | Prompts | Off 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.
- 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).
- 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.
- 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.
- 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
- Use the Azure OpenAI Responses API: handle guardrails and content filtering, Microsoft Learn
- Content filtering for Microsoft Foundry Models: scenarios, Microsoft Learn
- Configure content filters (classic), Microsoft Learn (severity thresholds in the classic portal)
- Default guardrail policies for Microsoft Foundry, Microsoft Learn
- Guardrails and controls overview, Microsoft Learn
- How to configure guardrails and controls, Microsoft Learn
- Harm categories and severity levels, Microsoft Learn
- Prompt Shields in Microsoft Foundry, Microsoft Learn
- Azure OpenAI frequently asked questions, Microsoft Learn (billing for filtered requests)
- Content streaming: cost considerations, Microsoft Learn
- Troubleshoot common HTTP errors for Azure OpenAI, Microsoft Learn
- Azure OpenAI responses REST reference: incomplete details, Microsoft Learn
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.