Prompt injection sits at the top of the OWASP Top 10 for LLM Applications for a reason: it is cheap to attempt, hard to fully prevent, and the blast radius keeps growing as we wire models into tools, email, file systems, and internal APIs. Unlike SQL injection, there is no parameterized-query equivalent that makes the problem disappear — the model cannot reliably distinguish instructions from data because, to the model, everything is tokens. What you can do is build layered defenses that make attacks expensive, detectable, and contained. On Azure, the most concrete building block for this is Azure AI Content Safety and its Prompt Shields API, which reached general availability in mid-2024 and has matured considerably since.

This article covers the attack taxonomy Prompt Shields is built around, how the service actually works, realistic configuration patterns, honest limitations, and the defense-in-depth architecture you should wrap around it.

The attack taxonomy: direct vs. indirect

Prompt injection splits into two families, and the distinction matters because they enter your system through completely different trust boundaries.

Direct attacks (user prompt attacks). The end user types malicious input into your chat interface, trying to override the system prompt or bypass the model's alignment training. Prompt Shields recognizes several recurring classes:

The classic goal is a jailbreak: elicit content the model was aligned to refuse, or extract the system prompt and other confidential context.

Indirect attacks (document attacks). Here the attacker is a third party who poisons content your system will later retrieve and feed to the model: a web page, an email in a summarization pipeline, a SharePoint document in a RAG index, a code comment an agent reads. The user who triggers the compromised session may be an innocent victim. This is the more dangerous class in enterprise settings because the malicious content arrives through a channel you treat as trusted data, and it can aim at real impact: exfiltrating data via tool calls, publishing fraudulent content, escalating privileges, or blocking capabilities. Microsoft's work on securing MCP servers treats indirect injection as a first-class threat for exactly this reason — agents that consume external content through tools are the new attack surface.

Any serious defense has to cover both families, which is precisely how Prompt Shields is structured.

How Azure AI Content Safety fits together

Azure AI Content Safety is a standalone Azure AI service (also integrated into Azure OpenAI content filtering in Azure AI Foundry) that provides several distinct detectors:

  1. Harm category filters — the original content moderation surface. Four categories (hate, sexual, violence, self-harm), each scored on a severity scale from 0 to 6, evaluated on both inputs and outputs. You configure block thresholds per category. These run by default on Azure OpenAI deployments.
  2. Prompt Shields — a unified API for injection attacks, with two sub-shields described below.
  3. Groundedness detection — checks whether an LLM output is supported by the grounding sources in a RAG scenario (more on this shortly).
  4. Protected material detection — flags model output (or input) that reproduces known copyrighted text (lyrics, articles, recipes) and, more recently, protected code. This is an IP-liability control, not a security control, but it rides the same plumbing.
  5. Custom blocklists and categories — term lists you curate yourself, matched exactly, plus trainable custom categories for domain-specific harms.

Note that Prompt Shields is not enabled by the default Azure OpenAI content filter — you must explicitly configure it, either per-request via the standalone Content Safety API or as part of a custom content-filter configuration on your Foundry deployments.

Prompt Shields in practice

The API is deliberately simple. You POST to /contentsafety/text:shieldPrompt with a userPrompt field and an optional documents array, and you get back booleans:

json
{
  "userPrompt": {
    "attackDetected": true
  },
  "documents": [
    { "attackDetected": false }
  ]
}

The critical architectural consequence: run the shield on retrieved content, not just user input. In a RAG pipeline, that means every chunk you plan to stuff into the context window should pass through the documents shield first. In an agent that reads email or web pages via tools, every tool response carrying untrusted text is a candidate. Since the documents parameter takes an array, you can batch the top-k retrieved chunks into one call to control cost and latency.

A minimal Python integration with the Azure AI Content Safety SDK looks like this:

python
from azure.ai.contentsafety import ContentSafetyClient
from azure.ai.contentsafety.models import ShieldPromptOptions
from azure.core.credentials import AzureKeyCredential

client = ContentSafetyClient(endpoint, AzureKeyCredential(key))

options = ShieldPromptOptions(
    user_prompt=user_message,
    documents=[chunk.text for chunk in retrieved_chunks],
)
result = client.shield_prompt(options)

if result.user_prompt_analysis.attack_detected:
    return refusal_response("I can't process that request.")
for i, doc in enumerate(result.documents_analysis or []):
    if doc.attack_detected:
        retrieved_chunks[i].quarantine()  # drop it from context

Two things worth stealing from this pattern: the shielded call happens before the LLM call (fail closed), and a flagged document is dropped rather than killing the whole request — a poisoned chunk in a ten-chunk retrieval shouldn't deny service to a legitimate user.

Groundedness and protected material

Groundedness detection answers a different question: given groundingSources, a query, and the generated text, is the output supported by the sources? The response includes an ungroundedDetected flag, an ungroundedPercentage, and per-claim details. You can scope it by domain (generic or medical) and task (summarization or QnA), and a correction feature (in preview at the time of writing) can rewrite ungrounded claims. Use it as a post-generation gate in RAG flows where hallucinated statements have real cost — customer-facing answers, compliance summaries, anything quoted downstream.

Protected material detection checks output against a catalog of known copyrighted content. If your app generates text or code that users will publish, this is cheap insurance on the output path, sitting next to your harm-category output filter.

Configuration patterns that work in production

A few patterns I've seen hold up:

Limitations, stated plainly

Prompt Shields is a classifier, and classifiers have error bars. Keep these in mind:

Defense in depth: the layers around the shield

Prompt Shields should be one layer, not the wall. A defensible Azure LLM architecture stacks:

  1. Least-privilege tool design. Agents get scoped credentials, read-only where possible, allow-listed actions, and hard spend/rate caps. This is the single highest-leverage control against indirect injection, because it bounds what a successful attack can do.
  2. Structured prompts. System prompt defines hierarchy explicitly; untrusted content is wrapped in delimiters with spotlighting tags; system prompts themselves are treated as secrets.
  3. Prompt Shields on user input and all retrieved/tool-returned text, failing closed.
  4. Harm and groundedness filters on output, plus protected-material detection where IP exposure matters.
  5. Human-in-the-loop gates for irreversible or high-impact actions — sending email, executing code, modifying records — regardless of how clean the input looked.
  6. Monitoring and red teaming. Continuous logging of shield verdicts, periodic adversarial testing (Azure AI Foundry includes evaluation tooling, and Microsoft's PyRIT framework is built for this), and alerts on attempt spikes.

The mental model is the same as network security: assume some attacks get through, and make sure the ones that do hit containment rather than keys to the kingdom.

Bottom line

Prompt injection is not solvable by any single API, including Microsoft's. But Azure AI Content Safety gives you a managed, continuously retrained detector for both direct and indirect attacks, groundedness checking for RAG integrity, and IP protections on output — all composable behind one endpoint. Wire Prompt Shields in front of every path untrusted text takes into your context window, fail closed, log everything, and spend the rest of your effort on least-privilege tool design. That combination won't stop every attack, but it changes the economics from "one weird trick" to sustained, noisy, detectable effort — which is what defense actually looks like.