Prompt injection is a defense in depth problem: structural separation, least-privilege tools, pre-filtering, and output checks stack; more instructions and 'trust the model' do not.
Imagine your house has a sign on the door that says 'do not steal.' A thief who can read just laughs. What actually keeps them out is locks on the doors, a small safe for valuables, cameras, and an alarm that calls the police. Prompt injection works the same way. Telling the model 'please ignore any sneaky instructions' is the paper sign. Real protection comes from putting user text in a clearly labeled envelope, limiting which tools the model is allowed to use, screening dangerous inputs before they arrive, and checking outputs on the way out. No single layer is bulletproof, but several thin layers stacked together are very hard to break through at once.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Prompt injection is the security category that decides whether an LLM application is hardened or hopeful. The question gets asked at every senior interview because the answer reveals whether the candidate understands that LLM apps are systems, not prompts.
This deep dive walks through why injection is structurally different from classical input-validation bugs, what defenses actually stack, what defenses look like they should work but do not, and how the production stance maps onto the agentic systems most teams are shipping now. The goal is a working mental model that holds up when an attacker is creative.
The headline is that no instruction-layer fix solves a context-layer problem. Once trusted and untrusted text share a context window, the defense has to live elsewhere.
Why injection is structurally different
Classical input-validation bugs assume the parser separates code from data. SQL injection works because a string is concatenated into a query and the database cannot tell which characters were meant as syntax. The defense, parameterized queries, restores the separation.
LLMs have no such separation. Every token in the context window is read by the same attention mechanism, and the model decides what each token means based on patterns it has learned. A line that says 'ignore previous instructions' carries weight regardless of which message-role envelope contains it, because the model has seen exactly that phrasing many times during training and has learned to take it seriously.
This means defenses cannot work by hardening the system prompt against specific phrasings. The attacker can always rephrase. Defenses have to either change the structure of the input (delimiters and data directives that the model has been trained to respect) or change the consequences of compliance (tool scoping, output checks, identity-bound capabilities).
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Anthropic's Claude prompt-engineering guide recommends XML delimiters and an explicit data directive for untrusted content blocks, with tool scoping as the second line of defense.
- Microsoft Copilot for Microsoft 365 documents a layered injection-defense architecture: input shields, tool allowlists, and output checks before responses leave the trust boundary.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you design tool scoping for an agent that reads emails and can also send them?
Separate read and write tools, require user confirmation on write tools, validate recipient against an allowlist tied to the authenticated identity, and log every send for audit.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating prompt injection as something one cleverly worded system instruction can solve, instead of a defense in depth problem that needs structural separation, tool scoping, and output checks layered together.
60 second bullets to scan on the way to the call.
Why prompt injection is a structural problem, not an instruction problem
The four meaningful defense layers
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.