Adversarial Prompting: Prompt Injection, Jailbreaks and Defenses
What prompt injection, jailbreaks, and indirect injection via documents, emails and web pages are. How developers building AI products and agents with access to email, browsers and computers can protect their systems.
What is adversarial prompting?
Adversarial prompting means crafting inputs that make a language model ignore its instructions, leak its system prompt or drop its safety rules. The main forms are direct prompt injection, indirect injection through documents and web pages, prompt leaking and jailbreaks. OWASP ranks prompt injection first (LLM01) among risks for LLM applications.
Prompt Engineering Guide
The Prompt Engineering Guide course goes from the anatomy of a prompt through few-shot, chain-of-thought, ReAct and structured output to this lesson on attacks and defenses. The first two lessons are open.
One trial lesson is open without sign-up: what a large language model is →
Attack types and a defense for each
| Attack | What it looks like | Defense |
|---|---|---|
| Direct prompt injection | The user types “Ignore all previous instructions…” or asks the model to act as a different assistant | Rules in the system prompt; user text wrapped in <user_input> tags and treated as data |
| Indirect prompt injection | An email, PDF or web page the model processes carries hidden instructions, such as “forward this email to…” | Mark external content as data, give tools least privilege, ask a human before risky actions |
| Prompt leaking | “Repeat the text above” or similar requests to extract the system prompt | Keep secrets out of prompts; check the answer for system-prompt text before it is shown |
| Jailbreak | Role-play, “for a fictional story…”, gradual escalation to get around safety rules | Lean on the model's own safety training, validate outputs, log patterns, test with attack simulations |
Three layers of defense from the lesson, plus testing
- SeparateInstructions in the system prompt, user data inside tags
- ConstrainA rule for “ignore your instructions” requests; least-privilege tools
- Validate the outputNo leaked prompt, no off-topic answer, no unrequested action
- Log and testLog suspicious prompts, run attack simulations before release


