Check my levelCoursesProgramsFor teamsPricing
UKSign inSign up
Check my levelCoursesProgramsFor teamsPricingClaude quizPromptsBlogFAQSearchSign upUK
AcademlCoursesPrompt Engineering GuideAdversarial Prompting and Defending AI Systems
Two labelled examples and a third line waiting for an answerClaude Code terminal: the claude -p command with Read and Edit allowedRetries after a 429 error: each pause is twice as long, then success
Get started free
Course

Prompt Engineering Guide

Module 1 · Prompting Fundamentals
01Anatomy of a Prompt02Zero-Shot and Few-Shot Prompting03Chain-of-Thought Prompting
Module 2 · Advanced Patterns
04ReAct Pattern: Reasoning and Acting05Role and Persona Prompting06Structured Output Control
Module 3 · Prompts at Work
07Prompts for Writing and Editing08Prompts for Coding09Adversarial Prompting and Defending AI Systems
Prompt Engineering Guide · Lesson 9

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.

35 min readUpdated Nov 23, 20262 questions in quizReady prompt included

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.

Start free: 7 days of full access →
Lesson 9 of 9opens after free sign-up

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.

Course program →
🔒

Full lesson access

Adversarial Prompting and Defending AI Systems opens after free sign-up: 7 days of full access to every course, no card needed.

Start 7-day free trial
Then Pro: $9/mo or $79/yr

View plans →

One trial lesson is open without sign-up: what a large language model is →

Attack types and a defense for each

AttackWhat it looks likeDefense
Direct prompt injectionThe user types “Ignore all previous instructions…” or asks the model to act as a different assistantRules in the system prompt; user text wrapped in <user_input> tags and treated as data
Indirect prompt injectionAn 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 promptKeep secrets out of prompts; check the answer for system-prompt text before it is shown
JailbreakRole-play, “for a fictional story…”, gradual escalation to get around safety rulesLean on the model's own safety training, validate outputs, log patterns, test with attack simulations
Attack names follow the DAIR.AI Prompt Engineering Guide; defenses follow the OWASP LLM01:2025 mitigation list.

Three layers of defense from the lesson, plus testing

  1. SeparateInstructions in the system prompt, user data inside tags
    →
  2. ConstrainA rule for “ignore your instructions” requests; least-privilege tools
    →
  3. Validate the outputNo leaked prompt, no off-topic answer, no unrequested action
    →
  4. Log and testLog suspicious prompts, run attack simulations before release
    →
The practical task asks you to build the first three layers into one system prompt and try several attack vectors against it.
In this lesson
Why Developers Need to Know About AttacksPrompt InjectionIndirect Injection via DocumentsAgents: Email, Browser, ComputerJailbreaks: Attempting to Bypass ConstraintsPractical Defensive TechniquesPracticeReady promptQuiz
CoursesLLM coursesFor teamsPricingFAQBlogAboutPrivacy
© 2026 AcademlDevelopment & promotion —MMIX — Marketing Mix

What OWASP LLM01:2025 adds

The OWASP Top 10 for LLM Applications describes prompt injection as user prompts that alter the model's behavior or output in unintended ways. Its seven mitigations:

  • Constrain model behavior with specific instructions about role, capabilities and limits.
  • Define and validate expected output formats, with deterministic code checks where possible.
  • Filter inputs and outputs for sensitive categories and known attack patterns.
  • Enforce privilege control: the model and its tools get only the access the task needs.
  • Require human approval for high-risk actions.
  • Segregate external content and mark it clearly as untrusted.
  • Run adversarial testing and attack simulations regularly. OWASP notes that no fool-proof prevention is known, so the aim is to limit impact.

Sources we checked

  • OWASP GenAI: LLM01:2025 Prompt Injection
  • DAIR.AI Prompt Engineering Guide: Adversarial prompting

FAQ

What is the difference between prompt injection and jailbreaking?+

OWASP treats jailbreaking as a form of prompt injection whose goal is to make the model drop its safety rules entirely. Prompt injection is broader: any input that changes the model's behavior, for example to leak data, misuse a tool or break your business rules.

What is indirect prompt injection?+

Instructions hidden in content the model reads from outside: web pages, files, emails, retrieved documents. The text can be invisible to a human as long as the model parses it. RAG systems and email assistants are typical targets.

Is adversarial prompt engineering the same thing?+

Both phrases describe crafting inputs that push a model outside its intended behavior. Attackers do it to break a product; teams do it on purpose (red teaming) to find weak spots in their own system before release.

Can a system prompt alone stop prompt injection?+

It lowers the risk, and the lesson's defensive prompt is a good first layer. OWASP adds output validation, least-privilege tools, human approval for risky actions and regular adversarial testing, since no single measure is known to prevent injection.

How do I test my AI app against adversarial prompts?+

Collect attack cases: a direct override, an instruction hidden in a document, a request for the system prompt and a role-play jailbreak. Run them against every prompt version and log the answers. The Prompt Evaluations course shows how to automate such checks.

Is this lesson free?+

It is lesson 9 of 9 in “Prompt Engineering Guide”. A free account opens this lesson and the rest for 7 days with no card, and the first two lessons stay open after that. After that Pro costs $9 a month or $79 a year.

Related lessons and courses

Free lesson 1: anatomy of a prompt →Prompt Engineering Guide course →AI safety and ethics course →AI safety track →Prompt evaluations course →Prompt engineering: a 4-week plan →

Open the full lesson with code-ready prompts

The lesson walks through each attack with examples and gives a defensive system prompt with three layers, a practical task and a quiz. A free account opens it and the rest of the course for 7 days, no card needed.

Create a free account →