Prompt Injection in LLM Apps
By Malcolm McDonald Founder, Editor-in-ChiefAuthor of Grokking Web Application Security
Prompt injection represents an easy way for an attacker to introduce unexpected behavior in a machine learning model.
- Prevalence
- Common
- Exploitability
- Easy
- Impact
- Harmful
What is prompt injection?
Prompt injection is an injection attack against applications built on large language models. The attacker places instructions in text the model reads, either typed directly or hidden in documents and web pages, so that the model ignores its system prompt. It can leak secrets, expose the system prompt, or trigger actions the application's authors never intended.
What you'll learn
- How direct and indirect prompt injection override a system prompt
- Why context manipulation and jailbreaking work against LLM apps
- How least privilege, structured prompting and output filtering limit the damage
Where this lesson counts
OWASP Top 10 for LLMs
Text that reaches the model changes what it does. The text can come from a user, a web page, a document, a tool result or stored memory, and the model cannot tell instructions apart from data.
Users extract the system prompt, tool definitions or other context the application hides from them. The damage is worst when that context holds credentials or is the only thing that enforces a rule.
In the lab, an injected prompt makes the chatbot reveal a database URL from its hidden instructions.
This lesson includes
Prompt Injection in LLM Apps lab
Watch scripted chats demonstrate direct injection, context manipulation, indirect injection and jailbreaking. Then try it yourself on an order support chatbot: tell it to ignore its previous instructions and get it to reveal the database URL.
How to prevent Prompt Injection in LLM Apps
The prevention guide covers six approaches, including:
- Implement Least Privilege Design
- Input Sanitization
- Structured Prompting
Prompt Injection in LLM Apps quiz
Four questions. Passing marks the lesson complete.
Glossary terms
Related lessons
Browse all 45 lessons
Sensitive Information Disclosure in LLMs
Your machine learning model may be leaking sensitive data without you knowing it.
Misinformation and Model Poisoning in LLMs
Machine learning is prone to bias and unreliability, and you need to put in safeguards to protect against that.
Slopsquatting (LLM Supply Chain)
When LLM tools hallucinate package names, attackers can register malicious packages with those names.
SQL Injection
If you are vulnerable to SQL Injection, attackers can run arbitrary commands against your database.
Further reading
- LLM01:2026 Prompt Injection OWASP
- AML.T0051: LLM Prompt Injection MITRE
- Prompt injection is not SQL injection (it may be worse) NCSC
- How Microsoft defends against indirect prompt injection attacks Microsoft
- Design Patterns for Securing LLM Agents against Prompt Injections arXiv
- The lethal trifecta for AI agents: private data, untrusted content, and external communication Simon Willison
- Fooling AI Agents: Web-Based Indirect Prompt Injection Observed in the Wild Unit 42
- Black Hat USA 2025 | From Prompts to Pwns: Exploiting and Securing AI Agents Black Hat
- Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection arXiv
- Prompt injection attacks against GPT-3 Simon Willison