Topic 7
No defence is complete, and wrap-up
No prompt-only defence is complete. OWASP LLM01:2025: "it is unclear if there are fool-proof methods of prevention for prompt injection." AI Engineering (Ch. 5, "Defenses Against Prompt Attacks"): as long as a system can do anything impactful, "the risks of prompt hacks may never be completely eliminated."
Predict first
Which defence breaks which step?
Lesson-design mapping · 6 defences · 2 attacks · not a measurement
Email asks to forward the inbox
- 1. The email's text is read into the contextless likely by scan untrusted text for attack phrases
- 2. The model treats the planted line as an instructionless likely by model trained on an instruction hierarchy, delimit and label untrusted text
- 3. The model calls forward_email to an outside address
- 4. Ten emails reach records@attacker.example
Harder, not stopped: every step can still happen
Web page asks for a link carrying the email
- 1. The page's hidden text is read into the contextless likely by scan untrusted text for attack phrases
- 2. The model treats the hidden comment as an instructionless likely by model trained on an instruction hierarchy, delimit and label untrusted text
- 3. The reply contains a link with the email in its address
- 4. Opening or previewing the link sends the email to the page's owner
Harder, not stopped: every step can still happen
Now add one blocking defence per attack. Least privilege or human confirmation stops the forwarding attack at the tool call; an output check stops the link. Two defences, chosen for where the damage happens, stop both: 24 of the 64 combinations do. The mapping is this lesson's design, not a measurement, and a real system has more paths than two.
To know whether defences work, the book suggests two numbers: the violation rate (successful attacks out of attempts) and the false refusal rate (safe requests refused). A system that refuses everything scores zero violations and is useless.
What to keep
- Instructions and data share one token stream, so the model can't reliably tell them apart.
- Direct injection comes from the user; indirect injection hides in retrieved pages, emails, documents and tool results.
- Label every part of the context by who controls it.
- Prompt and model defences reduce risk; least privilege, human approval and output checks block steps. Use both, and still plan for a miss.
Quick check