Join our Newsletter — 33% off our NHI Course
Home› Guides› Azure AI Content Safety and Prompt Shields Guide:…
Guide AI Platforms

Azure AI Content Safety and Prompt Shields Guide: Configure Jailbreak and Indirect Injection Detection

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 14 min read
On this page

Prompt Shields only protects the inputs you send to it, in the format it expects, at the intervention points you switch on. Teams often assume that an Azure OpenAI deployment with default guardrails is protected against prompt injection, yet document attack detection is off by default in Foundry, retrieved content that is not tagged as a document is checked like ordinary user text, and the standalone Content Safety API returns a verdict without blocking anything. This guide covers how Prompt Shields works in its two forms (the standalone Azure AI Content Safety API and Foundry guardrails), how to configure user prompt and document attack detection, Spotlighting, input limits, response handling, authentication, and how to measure it. It goes deeper than the Azure OpenAI and Azure AI Foundry Security Guide, which covers the wider platform, and is written for AI engineers, cloud security teams and detection engineers.

This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.

Key takeaways

  • Two attack types, two switches. User prompt attack detection (formerly Jailbreak risk detection) is on by default in Foundry guardrails; document attack detection is off by default and must be enabled for any deployment that reads retrieved or third party content.
  • The standalone API never blocks. text:shieldPrompt returns attackDetected for the prompt and each document; your application must block, exclude or escalate.
  • Documents must be marked as documents. In chat completions, untrusted content belongs inside <documents> tags with JSON escaping, or it is not analysed for document attacks.
  • Limits shape the design. The standalone API takes a prompt of up to 10K characters and up to five documents totalling 10K characters, so long retrieval contexts must be chunked or summarised before screening.
  • A classifier is one layer. Microsoft states Prompt Shields does not determine whether content is harmful, accurate, grounded or aligned with the application's task, and models are primarily trained and evaluated on English, so least privilege on tools and data still decides the blast radius.

What Prompt Shields detects

Prompt Shields is part of Azure AI Content Safety. Microsoft describes two detection targets: user prompt attacks, where the person typing tries to bypass system instructions or safety training (ATT&CK T1699 Direct Prompt Injection, ATLAS AML.T0054 LLM Jailbreak), and document attacks, where instructions hidden in documents, emails or web pages try to hijack the model session (ATT&CK T1698 Indirect Prompt Injection, ATLAS AML.T0051.001). Foundry also calls the second type indirect attacks or cross-domain prompt injection attacks. For the attack background see the Prompt Injection vs Jailbreaking guide.

ShieldInput fieldSubtypes Microsoft listsDefault in Foundry
User prompt attackuserPrompt (Content Safety API); user_prompt (chat completions prompt_shield)Attempt to change system rules; embedding a conversation mockup; role-play; encoding attacksEnabled
Document attackdocuments (Content Safety API); <documents> tagged content (chat completions)Manipulated content; allowing a compromised LLM to access system infrastructures; information gathering; availability; fraud; malware; plus the four user prompt subtypesOff: enable per guardrail

Related Content Safety capabilities sit beside Prompt Shields: the Analyze text and image APIs (hate, sexual, violence, self-harm at multiple severity levels), protected material text detection, the task adherence API for agent tool use that is misaligned, unintended or premature, and groundedness detection (preview). Microsoft's overview lists groundedness detection and some other preview capabilities as retiring on 30 April 2027, so check the overview before building on them.

Two ways to run it: standalone API or Foundry guardrails

AspectStandalone Content Safety APIFoundry guardrails (content filters)
CallPOST <endpoint>/contentsafety/text:shieldPrompt?api-version=2024-09-01Applied automatically to deployments or agents the guardrail is assigned to
Action on detectionReturns userPromptAnalysis.attackDetected and documentsAnalysis[].attackDetected; no blockingAnnotate, block, or both, per control
Model coverageAny model, any provider, because you call it yourselfDeployments and Foundry Agent Service agents the guardrail is assigned to
Intervention pointsWherever your code calls it (before the model, on tool output, on retrieved chunks)User input; for agents, document attacks can also apply at tool response for supported tools (preview)
Input sizePrompt up to 10K characters; up to five documents totalling 10K charactersMicrosoft notes the first 1,000 characters of text are moderated by Foundry guardrails in text scenarios
RegionsPrompt Shields listed in canadaeast, centralus, eastus, eastus2, northcentralus, southcentralus, westus, westus2, westus3 on the region pageGuardrails listed in a broader set including brazilsouth and canadacentral
Rate limitsF0: 5 RPS; S0: 1000 requests per 10 secondsPart of the model call

Decision guidance: use Foundry guardrails as the baseline for every Foundry deployment and agent, because they apply without code changes and can block. Add the standalone API where content reaches the model outside the guardrail's view: retrieved chunks assembled by your own orchestration, tool or MCP server responses, email and ticket bodies processed by background jobs, or models hosted elsewhere. Small teams can start with guardrails alone and annotate mode; larger organisations usually standardise a screening service in front of every model call so that one policy, one log schema and one exception process apply across providers.

Configuring guardrails in Foundry

  1. Create the guardrail: in the Foundry portal, open the project, select Guardrails then Create guardrail, choose User prompt attack or Document attack from the risk list, pick the intervention point and the action, then assign the guardrail to deployments or agents. In the classic experience the same filters sit under Guardrails + controls then Content filters.
  2. Turn on document attacks: enable Document attack for every deployment that uses retrieval (Azure AI Search, On Your Data, file search), reads email, browses the web or calls tools. For Foundry Agent Service, also enable it at tool response where the tool is supported.
  3. Choose the action: start in annotate so detections are returned without filtering, review hits, then switch to block. Microsoft's troubleshooting advice for false positives is the reverse move, from block to annotate, so use it for diagnosis rather than as a permanent state.
  4. Per-request settings: the chat completions example in Microsoft's docs (api-version 2024-10-01-preview) shows a prompt_shield object with user_prompt and documents, each with enabled and action, and spotlighting_enabled on documents. Pin the API version you test with.
  5. Harm thresholds: the four harm categories (Hate and Fairness, Sexual, Violence, Self-Harm) use thresholds of Low, medium, high; Medium, high; High; No filters; or Annotate only. For Azure OpenAI models, turning filters off or taking full control needs approval through the Azure OpenAI Limited Access Review: Modified Content Filters form.

Embedding documents correctly

Document attack detection in chat completions depends on marking untrusted content. Microsoft's document embedding guidance wraps each untrusted document in <documents> and </documents>, inside triple quotes, and JSON-escapes the content (for example a line break becomes \n and an accented character becomes a \u escape) so the safety system can parse it. By default the safety system checks the latest user content for harm categories and, optionally, Prompt Shields; tagged documents receive the additional document checks. Build the tagging into the code that assembles retrieved chunks, not into prompt templates that individual teams edit.

Spotlighting

Spotlighting (preview, off by default) tags input documents so the model treats them as lower trust than direct user and system prompts, by base-64 encoding the document content. Microsoft lists three trade-offs: it adds document tokens (cost), it can push large documents over input limits, and it is available only for models used through the Chat Completions API. A known side effect is that answers may mention that content was base-64 encoded; Microsoft's mitigations are disabling Spotlighting or a system prompt telling the model not to mention encodings. Pilot it on a retrieval-heavy deployment and compare answer quality before turning it on widely.

Calling the standalone API safely

The request body carries userPrompt (string) and documents (array of strings). The response returns userPromptAnalysis.attackDetected and one documentsAnalysis entry per document, in the same order. Design the calling code around these points:

  • Screen each source separately: send retrieved chunks, tool outputs and email bodies as documents, never concatenated into userPrompt, so a hit identifies the exact source to drop.
  • Respect the 10K limits: with at most five documents totalling 10K characters per call, batch chunks across calls. Do not silently truncate: an instruction placed after the cut-off is never screened.
  • Decide the failure mode: choose fail closed (drop the document or refuse) for agents with write tools or sensitive data, and record every time the screening call itself fails or times out.
  • Act per document: on documentsAnalysis[i].attackDetected, exclude that document from the context, log its source ID, and optionally quarantine it at the source for review.
  • Screen languages you serve: Microsoft states Prompt Shields models are primarily trained and evaluated on English and performance can vary for other languages, so evaluate each language your users write in.

Handling Foundry responses

  • Annotations: each configured control returns detected and filtered. A user prompt attack appears under prompt_filter_results[].content_filter_results.jailbreak; check your API version's schema for the document attack field name.
  • Blocked prompts: a filtered prompt returns HTTP 400 with error code content_filter.
  • Filtered completions: finish_reason is content_filter; in streaming, the last chunk carries it.
  • Filter unavailable: HTTP 200 with content_filter_error and the message "The contents are not filtered" in content_filter_results. Treat this as a screening failure and apply your fail-closed rule, because the response was not checked.

Where identity fits

The screening service is itself a non-human identity dependency. Microsoft's overview states Content Safety supports Microsoft Entra ID and managed identity, and that customer managed keys are available for encryption at rest. Call it with the managed identity of the application or orchestrator rather than a subscription key in the Ocp-Apim-Subscription-Key header. Disable keys by setting disableLocalAuth to true on the resource, enforced with the Azure Policy definition "Azure AI Services resources should have key access disabled (disable local authentication)". Microsoft notes the gateway can keep accepting previously valid keys for a few minutes to several hours after the change, so verify with a request using the old key and expect HTTP 401. See the Azure Managed Identities Security Guide, and store any remaining keys in Azure Key Vault.

Screening also does not shrink what an agent can do once an attack slips through. The agent's own Entra identity, its tool permissions and the data its retrieval index exposes set the impact; see the Azure AI Search for RAG Security Guide for the retrieval side.

Testing and rollout

  1. Inventory model entry points: list every deployment, agent and background job, and every source of untrusted content each one reads (search indexes, files, email, web, tools, MCP servers).
  2. Baseline in annotate mode: enable both shields with annotate for two to four weeks on production traffic and record detection rates per deployment, language and source.
  3. Build a regression set: keep an internal, access-controlled corpus of benign prompts, benign documents that look like instructions (runbooks, policy text, code comments) and red team samples from authorised testing. Run it on every model, API version or guardrail change. The RAG Security Test Plan Template gives a structure.
  4. Move to block by risk: block document attacks first on agents with write or send tools, then on retrieval deployments, then user prompt attacks on public-facing chat.
  5. Handle false positives: route blocked requests to a message that does not reveal detection details, log them, and review weekly. Fix by changing document tagging or content first; relax a guardrail only through a recorded exception.
  6. Roll back: switch the affected control from block to annotate on the specific guardrail (not all deployments), keep logging, and set a review date.

Detection and measurement

Prompt Shields results are useful security telemetry. Microsoft Defender for Cloud threat protection for AI services works with Prompt Shields and Microsoft threat intelligence to raise alerts for threats such as jailbreak, data leakage and credential theft, supports text tokens only, and integrates with Defender XDR so AI alerts can be correlated with identity and endpoint incidents. Enabling it at subscription level needs Owner or roles with the corresponding data actions. See the Microsoft Defender for Cloud Guide.

SignalWhere it comes fromUse
jailbreak detected or filtered annotationsprompt_filter_results in Foundry responsesPer-user and per-deployment attack rate; repeated attempts from one identity
Document attack hitsFoundry annotations or documentsAnalysis[].attackDetectedIdentify poisoned sources; quarantine and trace who wrote them
content_filter_errorcontent_filter_resultsScreening outages; responses that went unchecked
HTTP 400 content_filterApplication logsBlocked request volume and false positive review queue
Defender for AI Services alertsDefender for Cloud, Defender XDRCorrelation with identity and data access activity

Metrics:

  • Percentage of deployments and agents that read untrusted content with document attack detection enabled (target 100%).
  • Percentage of model calls with Prompt Shields in block mode, by risk tier.
  • Regression set results per release: detection rate on attack samples and false positive rate on benign samples, per language.
  • Count of unscreened responses (content_filter_error or screening call failures) per week, trending to zero.
  • Mean time from a document attack hit to source quarantine.
  • Percentage of Content Safety and Foundry resources with disableLocalAuth true.

Framework mapping

ControlNIST SP 800-53 Rev 5NIST CSF 2.0Threat reference
User prompt attack screeningSI-10 Information Input ValidationPR.PS-06T1699, AML.T0054, OWASP LLM01:2025 Prompt Injection
Document attack screening and document taggingSI-10, SI-3PR.PS-06T1698, AML.T0051.001, OWASP LLM01:2025
Annotation logging and Defender alertsAU-2, SI-4DE.CM-09, DE.AE-02AML.T0051
Regression testing of guardrailsSA-11 Developer Testing and EvaluationID.RA-01OWASP LLM01:2025
Keyless authentication to the screening serviceAC-6, SC-12PR.AA-05OWASP LLM06:2025 Excessive Agency (blast radius)

For the attack families see the MITRE ATT&CK T1698 Indirect Prompt Injection and MITRE ATT&CK T1699 Direct Prompt Injection guides.

Common failure patterns

  • Document attacks never enabled: the default guardrail covers user prompt attacks only, so retrieval and email-reading deployments run without indirect injection detection.
  • Untagged retrieved content: chunks are pasted into the user message without <documents> tags, so they are screened as user text rather than as documents.
  • Verdict ignored: the standalone API is called and logged, but nothing drops the flagged document, because the team assumed the API blocks.
  • Silent truncation: long contexts are cut to fit the 10K character limit and the unscreened remainder is still sent to the model.
  • content_filter_error treated as success: a screening outage passes unchecked responses straight through.
  • Shields as the only control: an agent with broad mail, file or payment tools relies on detection instead of least privilege and human approval for high-impact actions. See the Prompt Injection Incident Playbook for response.

Practitioner checklist

  • Enable Document attack detection on every deployment and agent that reads retrieved, emailed, web or tool content.
  • Wrap all untrusted content in <documents> tags with JSON escaping in shared orchestration code.
  • Run new guardrails in annotate mode, review hits, then move to block by risk tier.
  • Call the standalone shieldPrompt API for content outside guardrail coverage and act on each attackDetected result.
  • Chunk inputs to stay within 10K characters and five documents per call; never truncate silently.
  • Treat content_filter_error and screening timeouts as failures and apply a documented fail-closed rule.
  • Use managed identity, set disableLocalAuth to true and enforce it with Azure Policy.
  • Keep a regression set per language and run it on every model, API version or guardrail change.
  • Send annotations to your SIEM and enable Defender for AI Services threat protection.
  • Limit agent tools and data so a missed injection has a small blast radius.

Standards and references

Related NHI Mgmt Group resources: Azure OpenAI and Azure AI Foundry Security Guide · Prompt Injection Guide · LLM Jailbreaks Guide · OWASP LLM Top 10 LLM01 Prompt Injection Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.