15–25 min Updated

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

  • 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.

Sources