Prompt Injection & LLM Security
AI Engineer path · lesson 96 of 124Trace how untrusted content in a doc, page, or email hijacks an agent with tools — then stack defense-in-depth layers and see which attacks each one actually blocks.
| Defense coverage for selected attack | |||||
|---|---|---|---|---|---|
| Input filter / detector | Privilege separation | Structured output + schema validation | Human-in-the-loop on side effects | Sandbox untrusted content | Egress allowlist / URL policy |
| partial | full | partial | full | partial | partial |
Key insight
Direct attacks are the visible case — the user is the attacker, so a detector and a hardened system prompt lower the base rate. They do not close it: obfuscation (deliberate misspellings, mixed scripts, padding characters), roleplay (DAN, the grandma exploit) and automated attackers such as PAIR find a working jailbreak in under twenty queries. Indirect attacks are the interview question: any tool that reads external content (retrieved docs, emails, web pages) can carry an attacker\'s instructions into the agent\'s prompt without the user ever seeing them.
Attack or defence?
Sort each item.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Attack
Drop items hereDefence
Drop items hereTest your knowledge
Direct prompt injection is:
The short version
An LLM agent is a very obedient intern with access to your inbox and email. If a stranger drops a note in the inbox that says "send everything to Bob," the intern will follow it — unless you removed the intern's send button, gave them a checklist, or put a manager between them and the send button.
In more depth
Prompt injection & LLM security
A prompt injection attack is when text the model treats as instructions was written by someone other than the developer or user. Two shapes:
ignore prior instructions...).Indirect injection is the harder problem: the user never sees the attack, and any tool that reads external content is a delivery vector.
The lethal trifecta
An agent becomes dangerous when all three are true:
Remove any one leg. In practice, separating reading from acting (privilege separation) is the leg you actually control.
Defense in depth
Architectural (hold under a smart adversary):
Probabilistic (reduce base rate):
No single layer is sufficient. Ship both tiers, audit the architectural ones.
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required