What is prompt injection? Attacks, examples, defenses
Also called prompt injection attack, indirect prompt injection, LLM01
Definition
Prompt injection is an attack in which text supplied to a large language model, typed by a user or hidden in content the model reads, alters the application's intended behavior or output.
Prompt injection is a class of attack in which instructions planted in an LLM's input change what an application does. Simon Willison named the attack in September 2022, after Riley Goodside showed that GPT-3 prompts could be hijacked with malicious input. The OWASP Top 10 for LLM Applications 2025 ranks it first, as LLM01:2025.
How prompt injection works#
An LLM receives instructions and data in the same channel: one sequence of tokens. The model has no reliable way to separate the developer's instructions from content it was asked to process, so text that reads like an instruction can be followed as one. Willison compared the problem to SQL injection, where untrusted input is concatenated into a command string.
OWASP distinguishes two forms:
- Direct prompt injection: the user's own input alters the model's behavior, for example by asking a support bot to ignore its rules and reveal its system prompt.
- Indirect prompt injection: the payload sits in external content the model processes, such as a web page, email, PDF, or retrieved document. Greshake et al. demonstrated indirect attacks against Bing's GPT-4 powered chat in 2023.
Indirect injection is the larger risk for AI agents. An agent that reads an inbox and can send email can be instructed, by a message planted in that inbox, to forward private data. Each tool or MCP server an agent connects to widens what an injected instruction can do.
Prompt injection vs jailbreak#
OWASP describes jailbreaking as a form of prompt injection whose goal is to make the model disregard its safety protocols, for example to produce content it would normally refuse. Prompt injection is the broader category, and its target is usually the application: its data, its tools, and its instructions. A jailbreak attacks the model provider's rules; a prompt injection attacks the developer's.
Why prompt injection matters#
OWASP states that it is unclear whether any fool-proof prevention method exists, so defenses focus on limiting damage. Its recommended mitigations include:
- least-privilege access for every tool, with sensitive API calls kept in application code;
- human approval for high-risk actions;
- segregating and clearly labeling untrusted external content;
- validating outputs with deterministic code;
- regular adversarial testing that treats the model as an untrusted user.
Input and output guardrails reduce risk but do not remove it. The AI agents explainer covers how tool permissions shape an agent's attack surface.
Related terms
Guides that cover prompt injection
- What are AI agents? How agents work and when to use one
- What is the Model Context Protocol (MCP)? How it works
- What is an AI gateway? How it works and when you need one
- How to build an MCP server: a Python and TypeScript tutorial
- How to build an AI agent: a step-by-step guide in Python
- AI coding agents: how they work and how the major tools compare
- AI agent evaluation: metrics, graders, and how to test agents
- A2A protocol vs MCP: differences and when to use each
- LLM evaluation: a practical guide to evals, metrics, and judges
- What is tool calling? How LLM function calling works
- AI engineer roadmap: skills, projects, and resources by stage
Cite this definition
The AI Engineering Editors. "What is prompt injection? Attacks, examples, defenses." The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/prompt-injection
- Title
- What is prompt injection? Attacks, examples, defenses
- Author
- The AI Engineering Editors
- Publisher
- The AI Engineering
- Updated