Track 06 · Security & risk reviewLesson 02 of 10
Defending against prompt injection
Every document and tool result is untrusted input to an agent with tools.
- The FDE path · Stage 5 of 6
- 40 min read
- 60 min hands-on
- Pro
What you'll be able to do
01- Explain direct and indirect prompt injection, tool poisoning and rug pulls, and why no prompt or classifier fully prevents them.
- Identify the "lethal trifecta" (private data, untrusted content, external communication) in an agent design and break it.
- Apply structural defences: least privilege, capability separation, plan-then-execute, dual-model isolation, taint tracking and approval gates.
- Implement tool-definition pinning and review, datamarking of untrusted content, and a data-flow policy that stops tainted values reaching external sinks.
- Defend a residual-risk position to a CISO, with evidence from adversarial testing.
Before you start
- Guardrails the risk team can sign: rails, actions and why deterministic controls come first.
- MCP: connecting agents to the customer's systems: tool definitions as untrusted input; MCP's security considerations.
- Tools with scoped, auditable access and Approval gates and bounded autonomy: the controls that limit what an injected agent can do.
- Live web search as a tool: web content as an injection vector.
The short version
A language model cannot reliably tell instructions from data: everything in its context is text it may follow. Prompt injection exploits that. Direct injection comes from the user ("ignore your instructions"). Indirect injection arrives inside content the agent reads: an uploaded PDF, an email, a web page, a tool result, a memory, a code comment. Tool poisoning hides instructions in tool descriptions, and a rug pull changes a tool's definition after you approved it. Detection helps, but attackers can phrase injections endlessly, so the real defences are structural. Do not let one context combine private data, untrusted content and a way to send data out. Give each step only the tools it needs. Plan actions before reading untrusted content, or read it in a quarantined model that cannot act. Track which values came from untrusted sources and refuse to send them to external sinks. Pin and review tool definitions. Put a human gate on every consequential action. Then red-team the result and say plainly what risk remains.
Key takeaways:
- Treat every piece of text the model reads as potentially adversarial unless your own code wrote it.
- Injection is not "fixed" by a better system prompt or a classifier; those reduce rates, not the class.
- Break the lethal trifecta: never one context with private data, untrusted input and an exfiltration path.
- Control what the agent can do after it is fooled: least privilege, data-flow rules, gates.
- Tool definitions from third parties are code you are running in your model's head. Review and pin them.
Pro lesson
The rest of this lesson is in Pro.
The mental model, worked example, field note, failure table, exercise and self-check, with the voice tutor.
Pro opens this stage
Stage 5 · Prove it and pass review- 7 lessons, with the voice tutor
- Lab · Clean a golden set before you trust it, graded here
- Halden week 4 · First slice due
- Halden week 6 · Instructions hidden in an invoice
- The lab kit, to run Halden weeks on your machine
Also in Pro
- Every stage and specialisation, in full
- Every lab and every role project
- Halden weeks 2–10, on your record
- Every drill, live in the playground
- All solutions, plus the server judge
- Lab Assistant and every Teach with AI