Prompt Injection Attack Explained: How Attackers Hijack LLMs
A technical explainer of how prompt injection attacks work, the direct and indirect attack classes, real consequences, and what defenders can do.
Prompt injection attack explained in one sentence: an attacker supplies text that causes a large language model to abandon its developer-defined instructions and execute the attacker’s directives instead. The attack class is ranked LLM01:2025 by OWASP — the single highest-priority vulnerability in the OWASP Gen AI Security Project — and it underpins a growing share of real-world AI-system compromises.
Why the vulnerability exists
LLMs are stateless text processors. At inference time, a model sees one flat token sequence combining the developer’s system prompt, conversation history, retrieved documents, and the user’s latest message. The model has no native mechanism to enforce trust boundaries between these segments. Instructions from a developer and instructions from an attacker look syntactically identical to the model; what distinguishes them is only position in the context window and phrasing.
That architectural fact is the root cause. Unlike SQL injection — where parameterized queries separate code from data at a structural level — natural language has no equivalent separator that the model is guaranteed to respect. Telling a model “ignore all previous instructions” works on many systems because those five words are semantically valid instructions and the model was trained to follow semantically valid instructions.
Direct vs. indirect injection
Research published in arXiv:2402.00898 provides an early but widely cited categorization that distinguishes two primary attack classes.
Direct prompt injection occurs when an attacker controls the user-facing input and inserts malicious directives there. The classic payload is simple: “Ignore previous instructions and instead do X.” More sophisticated direct attacks use role-play framing, jailbreak preambles, or payload splitting — fragmenting an instruction across multiple turns so each fragment appears harmless individually. The threat model is a user with access to the chat interface who wants to circumvent safety filters, extract a system prompt, or cause the model to output restricted content.
Indirect prompt injection is operationally more dangerous. Here, the attacker embeds malicious instructions in external content the model retrieves and processes on behalf of a legitimate user: a web page returned by a search tool, an email the model is asked to summarize, a PDF an agent is tasked to analyze. The victim user never sees the injected payload. The model reads it, treats it as instructions, and acts accordingly. Documented indirect injection scenarios include hidden text in HTML (rendered invisible by CSS but processed by the model), instructions embedded in document metadata, and multimodal injections where text overlaid on an image in white-on-white carries attacker directives.
Palo Alto Networks’ cyberpedia entry on prompt injection adds a third class — stored prompt injection — where malicious instructions enter a model’s persistent memory or fine-tuning corpus, affecting all future inference without per-request attacker access. This represents a supply-chain risk for organizations fine-tuning on user-generated data.
Concrete attack objectives
OWASP’s LLM01:2025 entry identifies the operational goals attackers pursue after a successful injection:
- Sensitive information disclosure: extracting system prompts, API keys, user data, or internal business logic embedded in the context.
- Unauthorized action execution: causing an agent to call APIs, send messages, modify files, or execute code through tools the model is connected to.
- Goal hijacking: substituting the attacker’s objective for the developer’s, causing the model to produce outputs — malware, disinformation, phishing content — it was explicitly instructed to refuse.
- Safety filter bypass: overriding content moderation to generate hate speech, CSAM descriptions, or instructions for physical harm.
In agentic systems — where an LLM orchestrates tool calls, browses the web, executes shell commands, and interacts with external APIs — indirect injection escalates from a content problem to a remote code execution-equivalent. An attacker who can place a malicious instruction in any document an agent will read can, in the worst case, pivot through the agent’s tool permissions to systems the agent is authorized to access. Cases that reached that stage are catalogued in real world AI failure examples. For a review of how defenders are approaching this risk, see aisec.blog’s coverage of agent exploitation techniques.
What defenders can do
No single control eliminates prompt injection. The OWASP guidance and current practitioner consensus point to defense in depth:
Input and output filtering. Semantic classifiers trained to detect injection-style instructions provide a detection layer at both ingestion (checking external content before it enters the context) and generation (flagging output that looks like a system-prompt leak or a policy violation). These are imperfect — a sufficiently obfuscated payload can evade classifiers — but they catch common attacks. Tools implementing this class of defense are documented at guardml.io.
Privilege separation and least privilege. Agents should hold the minimum permissions required. A model tasked with summarizing emails does not need write access to the user’s calendar. Scoping tool permissions limits blast radius when an injection succeeds.
Human-in-the-loop gates for high-risk actions. Requiring human approval before an agent executes irreversible operations — sending email, deleting files, making purchases — breaks the automatic execution chain that makes indirect injection catastrophic.
Structured output enforcement. Defining and validating expected response formats makes it harder for injected instructions to alter the shape of model output in ways downstream systems would act on.
Adversarial red-teaming. Static configuration does not stay safe. Regular prompt injection testing against production contexts — not just generic benchmarks — surfaces bypass paths before attackers find them.
The gap OWASP flags
OWASP explicitly notes that prompt injection “cannot be fully prevented” through any known technique as of the 2025 update. Fundamental mitigation would require models to reliably distinguish instruction-level authority from data-level content — a research problem without a production-grade solution. This places prompt injection in a distinct category from most software vulnerabilities: the underlying weakness is architectural and not patchable by updating a library version.
For security operations teams, this means treating prompt injection as a persistent risk class rather than a patching queue item. Monitoring, rate limiting, anomaly detection on tool-call patterns, and regular red-team exercises are the operational controls, not a one-time fix. The tooling side is compared in best AI monitoring tools 2026.
Because the risk is persistent, the response plan matters more than the prevention plan. The incident-response playbook for AI systems covers the containment levers available when an injection has already executed through an agent, and AI incident reporting requirements covers what has to be notified when the resulting output exposed personal data or caused harm. Injection cases that reached the public record, with dates and primary sources, are filterable by modality and harm domain in the AI Incident Explorer.
Sources
AI Incidents — in your inbox
AI incidents, model failures, and adversarial-use cases — dated and sourced — delivered when there's something worth your inbox.
No spam. Unsubscribe anytime.
Related
Real World AI Failure Examples That Triggered Lawsuits
Real world AI failure examples, from a wrongful arrest in Detroit to a chatbot advising glue on pizza, and the court rulings and lessons they produced.
How We Log AI Security Incidents: Our Methodology
The methodology behind AI Incidents — how we verify sources, date-stamp claims, and decide what's news vs noise in the AI security incident beat.
Self-Driving Car Accident Causes: What Crash Data Shows
Sensor failures, software edge cases and fault attribution behind self-driving car accident causes, plus what NHTSA Standing General Order data shows.