1:1 mentoring with Big Tech AI engineers
System Design

Prompt Injection Defense

Why injection works (instructions and data share one stream), the four ways it arrives, why text filters only lower the odds, and the architecture that bounds the damage: the Rule of Two, taint, planner and reader splits, and adaptive testing.

Last updated

Production12 min readFirst readSecurity OverviewGuardrails & Safety

After this section you can

  • Explain why text filters lower the odds and cannot draw the boundary
  • Count the legs of an agent session and cut one of them
  • Design a code gate that decides an action from its arguments and taint
14

Prompt Injection Defense

Why text filters only lower the odds, and what in the architecture bounds a fooled model.

Key idea

You cannot filter injection away: instructions and data share one token stream. Decide in code what a fooled model may do, and let that code decide without reading the text it is defending against.

A fooled model is survivable when code checks its action
One token stream system, user, e-mail The model reads one stream Proposed action send_email(to=...) Text checks: read the words regex, classifier, reviewer model Code checks: read the arguments recipient, taint, approval, egress when the words fool it too the body is never read Can lose: the send goes out the step 03 regex passed 5 of 6 spellings Code decides: blocked, or held for a person tainted session, recipient not in contacts

Blue input, amber model, red action, green code. Pans sideways on a phone.

Related

More in System Design

Get full access to all 149 sections with code examples, diagrams, and interactive animations.

Unlock Premium