---
title: "What is prompt injection? Attacks, examples, defenses"
description: "Prompt injection is an attack where crafted text overrides an LLM application's instructions. Direct vs indirect injection, jailbreaks, and how to limit damage."
type: "glossary-term"
canonical_url: "https://theaiengineering.com/glossary/prompt-injection"
markdown_url: "https://theaiengineering.com/glossary/prompt-injection.md"
topic: "AI gateways and LLM routing"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
updated: "2026-11-06"
keywords: ["Prompt injection","prompt injection attack","indirect prompt injection","LLM01"]
citation: "The AI Engineering Editors. \"What is prompt injection? Attacks, examples, defenses.\" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/prompt-injection"
---

# What is prompt injection? Attacks, examples, defenses

Also called prompt injection attack, indirect prompt injection, LLM01.

> **Definition of Prompt injection:** 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](https://simonwillison.net/2022/Sep/12/prompt-injection/), after Riley Goodside showed that GPT-3 prompts could be hijacked with malicious input. The [OWASP Top 10 for LLM Applications 2025](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) ranks it first, as LLM01:2025.

## How prompt injection works

An LLM receives instructions and data in the same channel: one sequence of [tokens](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/system-prompt).
- **Indirect prompt injection:** the payload sits in external content the model processes, such as a web page, email, PDF, or [retrieved document](https://theaiengineering.com/glossary/retrieval-augmented-generation). Greshake et al. [demonstrated indirect attacks](https://arxiv.org/abs/2302.12173) against Bing's GPT-4 powered chat in 2023.

Indirect injection is the larger risk for [AI agents](https://theaiengineering.com/glossary/ai-agent). 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](https://theaiengineering.com/glossary/tool-calling) or [MCP server](https://theaiengineering.com/glossary/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](https://theaiengineering.com/glossary/human-in-the-loop) 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](https://theaiengineering.com/glossary/guardrails) reduce risk but do not remove it. The [AI agents explainer](https://theaiengineering.com/articles/what-are-ai-agents) covers how tool permissions shape an agent's attack surface.

## Related terms

- [Guardrails](https://theaiengineering.com/glossary/guardrails): Guardrails are programmatic checks placed around a large language model that validate, filter, or block inputs, outputs, and tool calls so an AI application stays within its safety, security, and policy limits.
- [Tool calling](https://theaiengineering.com/glossary/tool-calling): Tool calling is an LLM capability in which the model, given a list of tool definitions, outputs a structured request naming a tool and its arguments, which the application executes and returns.
- [AI agent](https://theaiengineering.com/glossary/ai-agent): An AI agent is a software system in which a large language model runs in a loop, calling tools, reading their results, and repeating until the task is complete or a stop condition is reached.
- [MCP server](https://theaiengineering.com/glossary/mcp-server): An MCP server is a program that exposes tools, resources, and prompts to AI applications through the Model Context Protocol, running locally over stdio or remotely over Streamable HTTP.
- [Retrieval-augmented generation (RAG)](https://theaiengineering.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation (RAG) is a technique that retrieves relevant passages from an external knowledge source at query time and adds them to a language model's prompt so the answer is grounded in that data.
- [Tool poisoning](https://theaiengineering.com/glossary/tool-poisoning): Tool poisoning is an attack in which a malicious or compromised MCP server hides instructions in a tool's description or schema, which the model reads as trusted context and may follow.
- [System prompt](https://theaiengineering.com/glossary/system-prompt): A system prompt is the set of developer-written instructions sent to a language model ahead of the conversation, defining its role, rules, output format, and tool use for every turn that follows.

## Guides that cover prompt injection

- [What are AI agents? How agents work and when to use one](https://theaiengineering.com/articles/what-are-ai-agents): AI agents are LLM systems that call tools in a loop until a task is done. Learn how the loop works, agents vs agentic AI, examples, failure modes, and limits.
- [What is the Model Context Protocol (MCP)? How it works](https://theaiengineering.com/articles/what-is-model-context-protocol): The Model Context Protocol (MCP) is an open standard for connecting AI apps to tools and data. Learn its architecture, transports, tool calls, and security.
- [What is an AI gateway? How it works and when you need one](https://theaiengineering.com/articles/what-is-an-ai-gateway): An AI gateway is a proxy between your apps and model providers. Learn how it works, its core features, AI gateway vs API gateway, and open source options.
- [How to build an MCP server: a Python and TypeScript tutorial](https://theaiengineering.com/articles/how-to-build-an-mcp-server): Learn how to build an MCP server with the official Python and TypeScript SDKs: tools, resources, transports, testing, client config, and production security.
- [How to build an AI agent: a step-by-step guide in Python](https://theaiengineering.com/articles/how-to-build-an-ai-agent): Learn how to build an AI agent from scratch in Python: when you need one, tool schemas, the agent loop, stop conditions, guardrails, evals, and tracing.
- [AI coding agents: how they work and how the major tools compare](https://theaiengineering.com/articles/ai-coding-agents): AI coding agents compared: how they differ from autocomplete, the four main categories, a comparison table of major tools, and how to evaluate and secure them.
- [AI agent evaluation: metrics, graders, and how to test agents](https://theaiengineering.com/articles/ai-agent-evaluation): AI agent evaluation guide: measure task success, tool use, safety, cost, and pass^k reliability with code graders, LLM judges, eval sets from traces, and CI.
- [A2A protocol vs MCP: differences and when to use each](https://theaiengineering.com/articles/a2a-vs-mcp): A2A protocol vs MCP: A2A connects AI agents to other agents, and MCP connects an agent to tools and data. Compare agent cards, tasks, transports, and security.
- [LLM evaluation: a practical guide to evals, metrics, and judges](https://theaiengineering.com/articles/llm-evaluation): LLM evaluation for engineers: build eval datasets, pick metrics, calibrate LLM-as-a-judge, evaluate RAG and agents, and gate every release in CI.
- [What is tool calling? How LLM function calling works](https://theaiengineering.com/articles/tool-calling): Tool calling lets an LLM request actions from your code through structured calls. Learn the request loop, parallel calls, structured outputs, security, and MCP.
- [AI engineer roadmap: skills, projects, and resources by stage](https://theaiengineering.com/articles/ai-engineer-roadmap): A practical AI engineer roadmap in seven stages, each with the skills to learn, a project to ship, and resources worth the time, from Python to production.

Part of the [AI gateways and LLM routing](https://theaiengineering.com/topics/ai-gateways) topic hub.

## 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: 2026-11-06
- URL: https://theaiengineering.com/glossary/prompt-injection
- Markdown: https://theaiengineering.com/glossary/prompt-injection.md
