Security Objective
Prompt injection detection identifies likely injection attempts and their consequences while a system runs. It combines signals from several layers of a request: the content that entered context, the model's behavior, the plan an agent proposes, the tool calls it makes and the actions that were attempted, allowed or denied. The result feeds a response policy, an alert queue and later investigation.
Detection matters because prevention is incomplete. Some injected content will reach the model, and some model outputs will reflect it. Detection shortens the time until someone notices, helps contain affected workflows and supplies the evidence needed to understand what happened. It does not prevent effects on its own.
Ownership Boundaries
| Control | Question it answers | Relation to detection |
|---|---|---|
| Prompt injection detection | Do correlated runtime signals indicate an injection attempt or effect | Owns signal correlation, detection logic, alerts and hand-off to response policy |
| Input / content inspection | Does this content representation raise risk signals | A content-level signal source that detection consumes |
| Data provenance | Where did content come from and how was it derived | Supplies context for correlation and scoping; detection never writes provenance |
| Spotlighting / data marking | How is untrusted content presented to the model | Marking is context; detection may observe whether marked content influenced behavior |
| Agent authorization | May this fully resolved action execute | Deterministic and independent; its decisions are a detection signal, not the reverse |
| Information flow control | May data with these attributes reach this sink | Deterministic and independent; denied flows are a strong detection signal |
| Human-in-the-loop | Does a selected action need a human decision | Detections can add review context; they never waive a required approval |
| Incident response | How is an incident contained, recovered and learned from | Detection opens and informs incidents; response owns the process |
Detection is broader than input / content inspection, which evaluates content before or during context assembly. Detection also watches what happens after the model has read that content. Plan drift detection and tool-chain analysis are specialised detection techniques listed separately in the defense taxonomy; this page covers their place in the overall detection architecture without replacing them.
Threat Model
The threat is text that changes what the model treats as instructions: typed by a user in a direct prompt injection, or embedded in retrieved data, messages, files or tool results in an indirect prompt injection. In agentic systems the concern extends to the plan and actions the model proposes, to propagation between agents and to persistence in memory or stores.
Assume the attacker can observe some outputs, can iterate, and may know which detectors exist. Assume also that attempts can be spread across turns, sources and steps so that no single event looks unusual. Detection is designed for these conditions and still cannot be complete.
Detection Results Are Evidence
Absence of a detection means no rule or model fired on what was observed. It says nothing about unobserved paths.
A detection indicates elevated likelihood. Triage establishes whether an attempt occurred and whether any effect followed.
An injection attempt that was denied by authorization is a different event from one that caused a disallowed action. Record both separately.
A low risk score never widens authority, and a high score does not itself block; the response policy does.
Trust Model
Detectors are system components, but the telemetry they read and the scores they produce remain variable. Only the response policy that consumes detections, and the enforcement controls that act independently of them, are system decisions.
Three rules follow. Telemetry fields that record system decisions must come from the enforcing component, not from model text. A detector's output never flows into authorization as permission. And missing telemetry is represented as unobserved, never as clean.
Signal Layers
- 01Content
Inspection findings on user input and external content, with the representation inspected.
- 02Context
Entry path, provenance, tenant, marking state and which sources were in context for the request.
- 03Model behavior
Outputs that address tools or hidden context, refuse or comply unusually, or change topic away from the task.
- 04Plan
Proposed steps that diverge from the user's stated objective or from the expected workflow.
- 05Tool calls
Tool selection, parameters, destinations and sequences relative to the task.
- 06Enforcement outcomes
Authorization denials, flow-control blocks, approval rejections and sandbox violations.
Individual layers are weak alone. Correlating them within one request, and across requests from the same principal, source or workflow, produces much stronger evidence than any single signal.
Enforcement Outcomes as High-Value Signals
Deterministic controls produce some of the most reliable detection signals. When agent authorization denies a proposed action, when information flow control blocks data from reaching an external sink, or when a human reviewer rejects an approval, the system has observed a concrete mismatch between what the model proposed and what policy allows.
Task Alignment and Plan Deviation
Many injections succeed by redirecting the task. Detection can compare the proposed plan and tool calls with the user's stated objective, the workflow's expected steps and the tools normally used for that task. Deviation is a signal, not proof: users change their minds and legitimate tasks vary. Dedicated plan drift detection formalizes this comparison; here it is one input to correlation.
Keep the representation of the user's objective authoritative. It should be captured by the application from the user's own turn or workflow definition, not reconstructed from model output that may itself have been influenced.
A controlled exercise, the Plan Drift Detection lab, practices distinguishing legitimate adaptation from material task or side-effect drift using authoritative application-side objectives. It is a deterministic simulation, not a detector test.
Sequence and Tool-Chain Signals
Individually plausible steps can combine into harmful effects: read a sensitive record, summarize it, then send the summary somewhere new. Sequence signals look at the chain rather than the step, for example sensitive reads followed by outbound actions, or new destinations appearing after external content entered context. Specialised tool-chain analysis deepens this; detection uses it as one layer.
Correlation Across Turns, Agents and Sessions
Attempts may span multiple turns, agent handoffs or sessions, for example when content written to memory affects a later request. Correlation needs stable identifiers: request and conversation IDs, provenance references for content items, agent and workflow identifiers and the principal on whose behalf actions ran.
For agentic and multi-agent systems, record each hop with its inputs and outputs so a detection can be traced back to the content that first entered context.
Detector Types
| Family | Strengths | Weaknesses |
|---|---|---|
| Rules and signatures | Transparent, fast, testable, explainable | Narrow; paraphrase and new techniques avoid them |
| Behavioral baselines and anomaly | Find unusual tool use or destinations without knowing the technique | Noisy; need stable baselines; slow to adapt to new workflows |
| Classifier or model-based | Generalize across phrasing and context | Opaque; can be influenced by the content they analyse; need evaluation and versioning |
| Policy-outcome correlation | Grounded in deterministic decisions | Only sees what enforcement already observed |
Record which family and version produced each detection. Combining families improves coverage, but the combined result is still probabilistic.
Detector Integrity and Isolation
A model-based detector reads the same untrusted content as the system it protects and can be influenced by it. Constrain its output to a fixed schema, give it no tools and no authority, and run it in a context separate from the main task. Where possible, prefer detectors that read structured telemetry over detectors that read raw natural language.
When a detector is unavailable or times out, record the gap as unobserved. Whether the workflow continues, degrades to a restricted mode or stops is a risk-tier decision for the response policy.
Inline, Near-Real-Time and Retrospective Detection
| Mode | When | Typical use |
|---|---|---|
| Inline | Before a step completes | Trigger routing or pause before a high-impact action; strict latency budget |
| Near-real-time | Seconds to minutes after an event | Alerting, session containment, correlation across steps |
| Retrospective | Hours to days later | Hunting, re-scanning stores with improved detectors, finding persistence |
Inline detection must be fast and conservative in scope; it complements, but does not replace, deterministic checks at the same boundary. Retrospective detection is essential for persistent injection, because new detectors can find content that was stored before they existed.
Response Policy
A response policy outside the model maps detections, confidence, workflow risk tier and affected assets to actions. Higher-authority workflows justify lower thresholds and stronger responses.
Store the detection for correlation and later hunting without changing the workflow.
Open a triage item with the evidence bundle attached.
Route the session to a mode with fewer tools, no side effects or narrower scopes.
Hold a pending action for human review; see human-in-the-loop for approval design.
Terminate the session, revoke short-lived credentials or quarantine affected content.
Alert Quality and Triage
Alerts that analysts cannot act on are ignored. Each alert should carry the correlated evidence: which signals fired, the content items and provenance involved, the model output and proposed actions, and what enforcement decided. Group related signals into one case rather than emitting one alert per event.
Define severity from impact potential and observed effect rather than detector confidence alone. A low-confidence signal attached to a denied external data transfer can deserve more attention than a high-confidence content match in a read-only workflow.
False Positives, False Negatives and Drift
False negatives are assumed; downstream enforcement exists for them. False positives cost analyst time and user trust and push teams toward suppressions. Measure both separately and review every suppression rule with an owner and expiry.
Workflows, tools, content mix, model versions and attacker techniques change. Version detectors and thresholds, re-run a labelled regression set on each change and watch detection rates per workflow for shifts that indicate drift or silent breakage.
Telemetry Design
Record for each request and step
- Correlation IDs for request, conversation, session, agent and workflow
- Principal, tenant and the authoritative user objective
- Content items in context with provenance references and marking state
- Inspection findings with inspector version
- Model output references and proposed plan and tool calls
- Enforcement decisions with the deciding component and policy version
- Detector outputs with family, version and confidence
- Unobserved state and reason when a signal source was unavailable
Telemetry can contain sensitive content and hidden context. Apply access control, minimization and retention rules at least as strict as those for the underlying data, and keep system decision fields separate from model-generated text.
Privacy and Retention
Detection needs enough data to reconstruct events, but full prompt and output logging can expose personal data, secrets and hidden instructions. Prefer references, hashes and excerpts where they suffice, restrict access to full records, and set retention by purpose. Record who accessed detection evidence.
Worked Scenario
Synthetic example. An internal assistant helps an employee prepare a vendor comparison. It can read shared documents, search the web and send email on the user's behalf. A retrieved web page contains a synthetic test marker phrased as an instruction to email an internal pricing sheet to an external address.
| Layer | Observation | Outcome |
|---|---|---|
| Content inspection | Instruction-like signal in the web page text | Low-confidence finding recorded; content marked and kept in context |
| Plan | Plan adds a send-email step not implied by the user's objective | Deviation signal |
| Tool calls | Read of the pricing sheet followed by a send to a new external domain | Sequence signal |
| Information flow control | Internal-confidential data to external recipient | Flow denied deterministically |
| Correlation | Three signals plus a denial within one request, after one external source entered context | High-severity alert with evidence bundle |
| Response policy | Send-capable workflow, confirmed denial | Session restricted to read-only; source flagged for review |
In a benign variant, the user explicitly asks to email a public summary to a colleague. The plan matches the objective, the data is public, the flow is allowed and the send step goes through the user's own confirmation. No alert is raised.
What the Scenario Proves and Does Not Prove
It shows correlation turning several weak signals and one deterministic denial into an actionable alert, and it shows the harmful effect being prevented by flow control, not by detection. It does not show that detection would catch a paraphrased or multi-session variant, that the web page author was malicious, or that the benign variant was risk-free. Prevention is attributed to IFC; visibility and containment to detection and response policy.
Incident Response Relevance
When a detection escalates
- Preserve telemetry, content items and enforcement records under the correlation ID
- Establish whether any disallowed effect occurred, separately from the attempt
- Use provenance to find the source content and its derivatives, including memory and indexes
- Contain the workflow and revoke or rotate credentials the session could reach
- Quarantine affected content and re-scan stores with current detectors
- Add a sanitized synthetic case to the regression set and review thresholds
A detection starts an investigation. Conclusions about compromise follow from evidence of effects, not from the alert itself.
Controlled Testing
Test detection end to end with synthetic markers and labelled scenarios that exercise each signal layer: content, plan deviation, tool sequences and enforcement outcomes. Run tests in isolated environments with test identities, non-production data and harmless sinks. Label each scenario with the expected signals and response. Do not build or publish reusable payload libraries; the goal is to measure detection and response behavior.
Metrics
Each measure keeps its own denominator. There is no composite score, and benign task utility is reported separately.
| Measure | Numerator | Denominator |
|---|---|---|
| Telemetry coverage | Requests with all required signal sources recorded | Requests in scope |
| Detection recall | Labelled adversarial-style scenarios that produced the expected detection | Labelled adversarial-style scenarios executed |
| False-positive rate | Benign scenarios that produced an alert | Benign scenarios executed |
| Enforcement-signal capture | Policy denials linked to a detection record | Policy denials |
| Alert actionability | Alerts triaged with a clear disposition | Alerts raised |
| Unobserved rate | Requests with at least one signal source missing | Requests in scope |
| Detection latency | Distribution (for example median and high percentiles) from event to detection | Detected events |
| Time to containment | Distribution from alert to response action | Alerts with a response action |
| Regression pass rate | Regression scenarios with expected result | Regression scenarios run |
| Benign task utility | Benign tasks completed acceptably | Benign tasks attempted |
Common Mistakes
- 01Detection as prevention
Relying on alerts where deterministic enforcement is needed.
- 02Low score as permission
Allowing more authority when detectors report low risk.
- 03Content-only view
Watching inputs but not plans, tool calls or enforcement outcomes.
- 04Model-sourced facts
Taking decision or identity fields from model text instead of the enforcing component.
- 05Silent gaps
Treating missing telemetry or detector outages as clean.
- 06Alert floods
One alert per event without correlation, leading to suppression and neglect.
Implementation Checklist
Before relying on detection
- Signal layers defined: content, context, behavior, plan, tools, enforcement
- Correlation IDs and provenance references propagated across steps and agents
- Authoritative user objective captured outside model output
- Enforcement decisions emitted as security telemetry
- Detectors isolated, versioned and constrained to fixed output schemas
- Response policy outside the model that only narrows authority
- Unobserved states recorded and reported
- Regression set, drift monitoring and suppression review in place
- Authorization, flow control and least privilege enforced independently
Standards and Sources
Standards and guidance referenced
- OWASP
- LLM01:2026 Prompt Injection
- NIST
- AI 100-2e2025 (taxonomy and terminology)
- Microsoft
- Defend against indirect prompt injection attacks (vendor guidance), Prompt Shields in Azure AI Content Safety (product documentation)
On source use: OWASP LLM01:2026 is the current classification for prompt injection. NIST AI 100-2e2025 is used only for terminology; it is not a detection standard. Microsoft's guidance on indirect prompt injection is vendor guidance that recommends layering probabilistic and deterministic mitigations and names detection-oriented techniques such as prompt shields, plan drift detection and tool chain analysis alongside information flow control, least privilege and human-in-the-loop. Microsoft's Prompt Shields documentation describes one product's detection of user prompt and document attacks within its documented scope; it is cited as an example, not as a general model. No detection efficacy figures are claimed on this page.
Frequently Asked Questions
Can detection prevent prompt injection?
Not on its own. It can trigger responses that reduce authority, but prevention of harmful effects depends on deterministic controls such as authorization and flow control.
Does no alert mean nothing happened?
No. It means no detector fired on what was observed. Unobserved paths and missing telemetry must be reported as gaps.
Is an alert proof of an attack?
No. It indicates elevated likelihood. Triage establishes whether an attempt occurred and whether any effect followed.
How is this different from input / content inspection?
Inspection evaluates content. Detection also correlates model behavior, plans, tool calls and enforcement outcomes across steps.
Why are authorization denials useful for detection?
They are deterministic observations that the model proposed something policy does not allow, which makes them strong signals.
Should a model be used as a detector?
It can be one layer if isolated, constrained to a fixed output schema and given no tools. It can itself be influenced by the content it reads.
Can a low risk score unlock more tools?
No. Response policies only narrow authority. Least privilege sets the ceiling independently.
Why keep retrospective detection?
Stored content can persist for a long time. Improved detectors can find it later, which matters for persistent injection.
What should be logged?
Correlated identifiers, provenance references, proposed actions, enforcement decisions and detector outputs, with privacy controls matching the underlying data.
Can a vendor detector solve prompt injection?
No. Vendor guidance itself recommends layered defenses; a product detector is one signal source among several.
References
- OWASP GenAI LLM Top 10 2026 (LLM01:2026 Prompt Injection)OWASP GenAI Security Project · GuidanceReviewed 2026-09-25
- Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations, NIST AI 100-2e2025NIST · Standard · 2025-03Reviewed 2026-09-25
- Defend against indirect prompt injection attacksMicrosoft Learn · GuidanceReviewed 2026-09-25
- Prompt Shields in Azure AI Content SafetyMicrosoft Learn · Technical documentationReviewed 2026-09-25