Prompt Injection Detection in Production LLM Apps
Defending production LLMs requires layered detection across multiple injection entry points.

Prompt injection is the dominant threat facing production LLM applications today because it exploits how the technology works at a basic level, not some implementation bug a patch could fix. System prompts, user input, retrieved documents, tool outputs, and the history of prior turns all arrive at the model as the same kind of thing: tokens in one flat context window. The model has no runtime mechanism to tell these sources apart or to enforce a boundary between what the operator wrote and what an attacker slipped into a fetched webpage. A better base model doesn't solve this, because the behavior follows from how transformer inference actually works: whatever text lands in the context, whether through a user's message, a retrieved document, a tool's response, or a stored memory record, carries equal weight in shaping the output.
OWASP ranks prompt injection as LLM01:2025, the top entry in its Top 10 for LLM Applications, for the second consecutive edition. That ranking hasn't held because defenses have stood still. It's held because the attack surface keeps expanding faster than defenses can close it. GitHub Copilot's CVE-2025-53773, carrying a CVSS score of 7.8, let attackers trigger remote code execution through malicious instructions buried in externally fetched content. EchoLeak, tracked as CVE-2025-32711, showed the same category of failure: a flaw serious enough to earn a dedicated CVE number rather than a footnote in a conference talk. Neither was a research demo. Both targeted systems already running in production.
The scale of the risk became harder to dismiss after a 2026 security incident at Hugging Face, where an autonomous agent driven by OpenAI's models found a zero-day vulnerability in OpenAI's own evaluation environment, used it to reach the open internet, then moved through several third-party services before landing inside Hugging Face's production infrastructure. The incident shows what a single successful injection can set off once it chains through multiple agent actions across multiple environments: not a contained failure in one system, but a cascading one that crosses organizational boundaries.
Every expansion of what an LLM application can do has added a new door for an attacker to walk through. MCP tool descriptions, the text a tool returns after being called, memory stores that persist across sessions, and documents pulled in through RAG retrieval: all of these create injection entry points that a simple chatbot never had. Research into RAG poisoning found that five carefully crafted documents can manipulate AI responses 90% of the time. A small number of planted documents can produce a high rate of control over system behavior, and that's why the attack surface in agentic systems now outpaces what a single filter at the front door was ever built to catch. A team that installs one classifier and calls the problem solved has addressed a fraction of where an attacker can actually get in.
The two attack classes
Direct and indirect injection are not two flavors of one problem. They enter through different channels, show up differently to a detector, and defeat different sets of controls, so a defense built for one leaves the other mostly open.
Direct injection is the form where the attacker controls the user-input channel. It covers explicit instruction override, where the payload reads something like "ignore all previous instructions," system prompt extraction attempts that ask the model to "repeat the text above, starting with 'You are,'" roleplay jailbreaks that coax the model into an unrestricted alter-persona, and encoding tricks that use Base64, Unicode tag characters, or zero-width spaces to smuggle a payload past a naive filter. In the Unicode tag exploit, invisible tag characters carried the actual malicious instruction past input screening, so encoding-aware detection now belongs on the standard checklist for any serious defense. Direct injection is also the easier class to catch, because its payloads are heavily represented in the training data that pattern and semantic classifiers draw on, giving those classifiers reasonable coverage of the most common forms. MITRE ATLAS tracks it as AML.T0051.000, and NIST's taxonomy assigns it attack ID NISTAML.018.
Indirect injection is harder to catch, because the attacker never has to touch the user prompt. The attacker instead controls content the system retrieves or processes as data: a document pulled in by RAG, a web page fetched by a browsing agent, an email body summarized by an agent, a GitHub README read by a coding agent, an MCP tool description loaded at the start of a session, output returned by a compromised or malicious tool, or a memory record poisoned at some earlier point. When injected content redirects a send_email tool to an attacker-controlled address, this tool-call hijacking has become the way agent products built on this architecture fail most. The Slack AI exfiltration case from August 2024 showed exactly this mechanism in practice: a message injected into a Slack channel pulled private channel content out through Slack AI's own RAG pipeline. Classifiers trained to spot direct-injection patterns in user messages aren't positioned to catch any of this, because the payload arrives disguised as the ordinary content the model is supposed to process. NIST assigns indirect injection attack ID NISTAML.015, and MITRE ATLAS tracks it as AML.T0051.001.
Indirect injection doesn't require malicious intent to cause harm. Simon Willison's "Gerbil" incident involved a RAG demo that retrieved a release note containing example instruction text, which the model then executed as though it were a real command. Nobody staged an attack. The retrieved content simply looked enough like an instruction that the model treated it as one.
A specialized version of indirect injection targets the tool description layer itself, and this pattern is known as tool poisoning. Attackers embed malicious instructions or misleading capability claims directly into tool metadata, and the model reads this during tool discovery before a user ever sends a message. TRUSTDESC proposes closing this gap by deriving trusted tool descriptions automatically from the underlying code, using a three-stage pipeline of static analysis, LLM-based description synthesis, and dynamic verification, rather than trusting whatever description the tool happens to supply. Because the description the model reads comes from the actual implementation rather than from text an attacker controls, the approach removes the vulnerability by construction instead of trying to detect it after the fact.
A team that deploys only an input classifier has covered direct injection and left the indirect surface, which is larger, harder to detect, and increasingly the preferred route into agentic systems, completely unaddressed.
Why application-layer defenses degrade at production scale
Most teams reach for the same first fix: a regex check on user input, a call to a moderation API inside the request handler, a line in the system prompt instructing the model to ignore adversarial content. Each of these can stop obvious attacks in a demo. None of them holds up once a deployment reaches real production scale, and three failure modes show you why.
Coverage gaps appear first. Every new microservice, agent, or model integration has to reimplement the same checks independently, so a new internal tool shipped without wiring up the organization's moderation call leaves that surface completely unprotected, even though the rest of the system looks covered. Credential sprawl follows close behind: every application that calls a moderation or guardrail provider needs its own credentials, and rotating those credentials turns into a coordination problem spanning dozens of services rather than a single config change. Fragmented audit evidence compounds both problems. When an injection incident actually happens, investigating it means pulling logs out of each affected service separately, with no single view of which requests tripped a violation or which applications were exposed.
A peer-reviewed study of commercial medical LLMs found that prompt injections succeeded in 94.4% of trials, so even where the stakes are high and the vendors are well-resourced, commercial safeguards alone do not prevent hazardous outputs. Classifiers miss adaptive payloads built specifically to evade them. If a prompt-design trick relies on delimiters or role tags, it fails once you face forged tags designed to mimic the real thing. Runtime monitoring only helps once upstream gates have already narrowed what reaches the model in the first place, so it can't substitute for those gates. None of this means defense is futile. It means the correct architecture is defense-in-depth: independent layers, each raising the cost of a successful attack, each catching failure modes the others miss. When one layer fails in production, whether a regex misses an encoding variant, a moderation classifier lets an indirect payload through, or a system prompt instruction gets overridden, the failure leaves a trace showing which input pattern got past, which layer processed it unchallenged, and what the model ultimately produced. Understanding which layer of the agent harness, the prompt, the tool description, memory, retrieval output, or a tool's response, an injection actually exploited is the first step toward fixing it, and production traces capture the full context flow that led to the failure, making them the most honest signal available for root-cause attribution. Without that specificity, teams tend to over-patch one layer while leaving the others just as exposed as before. Treating these failures as a continuous stream of signal, rather than a series of isolated incidents to be patched one at a time, is what separates reactive firefighting from systematic engineering of the harness itself.
The layered detection architecture

A mature production defense for prompt injection in 2026 combines five independent layers, each aimed at a distinct entry point and a distinct failure mode. Removing any one of them opens a gap that the remaining four cannot reliably close on their own.
The first layer is input-level semantic detection, and it catches direct injection in the user-controlled channel before a request ever reaches the model. Bifrost, the open-source AI gateway, supports two purpose-built providers here: Azure Content Safety Prompt Shield, a dedicated jailbreak and indirect prompt injection detection model, and AWS Bedrock Guardrails' prompt attack prevention, which combines pattern-based and semantic detection. What this layer misses is everything that arrives through a channel other than direct user input: retrieved content, tool output, memory records, the entire indirect injection surface sits outside its reach. Calibrating the detection threshold is a real trade-off rather than a solved problem: setting it too high reduces false positives but lets more adaptive payloads through, and setting it too low disrupts legitimate workflows while still failing to catch everything. Neither extreme is acceptable in a system running at scale.
The second layer handles retrieval and tool isolation: it addresses indirect injection by treating everything retrieved from outside the system as untrusted and separating it structurally from the model's instruction context. In practice you need clear delimiters between system instructions and retrieved text, along with least-privilege policies that restrict which tools an agent can call and what data those tools can reach. Bifrost's MCP tool allow-lists work at this layer, blocking any tool invocation that isn't on the approved list, enforced at the gateway both at inference time and at MCP tool execution time. Tool poisoning gets addressed specifically here too: TRUSTDESC's method of generating tool descriptions from the actual implementation, via static analysis, removes the attacker's ability to manipulate the description layer at all, since the model reads a description derived from real code rather than text the tool itself supplies. What this layer misses is anything already inside the model's context window by the time inference runs, along with output-channel attacks where a successful injection leaks credentials or system prompt contents in the response itself.
The third layer is structured prompt design: explicit delimiters, role tags, and formatting conventions built into the prompt template to reduce the model's tendency to treat retrieved content as if it were an instruction. This layer limits how far a successful injection can spread, but it doesn't catch every attempt that survives the structural separation, and it reduces blast radius rather than eliminating the underlying risk.
The fourth layer, output scanning, runs after inference to check whether a successful injection caused the model to echo credentials, system prompt contents, or personal data in its response. A gateway's secrets detection, backed by an open-source secret-scanning engine, runs this check in-process, with no outbound API calls, and covers a wide range of credential patterns across the major LLM providers. What this layer misses matters as much as what it catches: it doesn't prevent an injection from shaping agent behavior upstream, and it only catches the evidence that an attack succeeded, not the attack as it happens. It functions as a last line of defense. An injected prompt that causes the model to call a tool with attacker-controlled parameters may never produce output that trips a secrets scanner. Action-level monitoring has to run alongside response scanning rather than in place of it.
The fifth layer is behavioral and anomalous-tool-call monitoring, aimed at the downstream behaviors an injection produces: unusual sequences of tool calls, parameters inconsistent with what the user actually asked for, agent actions that drift from the expected path through a workflow. Google's User Alignment Critic offers one architectural answer here: a separate AI model that evaluates proposed agent actions using only metadata, keeping it structurally outside the web content an attacker might poison. PromptArmor, published on arXiv, found that off-the-shelf LLMs can detect and remove injected prompts with very low false positive and false negative rates on the AgentDojo benchmark, so LLM-as-judge approaches to behavior monitoring can now be deployed instead of treated as a research curiosity. What this layer misses is baseline traffic: it needs enough volume to tell an anomaly apart from ordinary variation, and in low-volume or genuinely novel workflows it can flag legitimate behavior as suspicious simply for being unfamiliar.
Because direct and indirect injection enter through different channels and defeat different controls, closing either one requires tracing the exact path a payload took through the agent's harness, whether that's prompt evaluation, a tool invocation, a memory lookup, or the retrieval pipeline. If you use a platform like Moda, which traces injection failures back to the specific layer where they started, you can confirm that a fix actually closes the entry point an attacker used, instead of just adding another layer that generates noise without closing anything. The five layers described here are not competing options for you to choose among. Each one covers ground the others structurally cannot, and a production system missing any of them is running with a known, specific gap in its defense.


