Prompt Injection Defense
The goal is blast-radius control
Prompt injection is not a string-cleaning problem. Tool outputs are model inputs. A web page, email, PDF, issue body, spreadsheet, or source file can contain instructions that try to override the developer’s intent.
There is no known reliable sanitizer that lets a model perfectly distinguish trusted harness instructions from malicious instructions inside retrieved content. The working posture is to assume injection will sometimes succeed, then design the system so a hijacked model cannot do much damage.
That changes the security question from “How do we make the model ignore the malicious text?” to “What can the model reach if it fails to ignore it?”
Key ideas
- The lethal trifecta: Simon Willison’s framing is private data, untrusted content, and external communication. When an agent has all three, prompt injection can become data exfiltration. Break any one edge and the worst case is smaller.
- Least privilege per tool: A web fetcher should not be able to send email. A code editor should not automatically reach the network. A database reader should not also have production write access.
- Permission gates: Writes, sends, deploys, purchases, deletes, and credential access need explicit approval. The approval prompt should show the action and consequences, not a vague “allow tool call?” message.
- Content provenance labels: Mark content as trusted instructions, user input, retrieved public web, internal document, tool output, or generated summary. Labels help the model reason, but they are not a security boundary by themselves.
- Deterministic output channels: Avoid automatic link fetching, image rendering, shell execution, or webhook delivery from model-generated text. Any outbound path can become an exfiltration path.
Threat model
Prompt injection is most dangerous when an agent can read secrets and send information somewhere else. Examples:
- A support-ticket agent reads a malicious ticket and has access to private customer records.
- A coding agent reads a README from a dependency and can run shell commands.
- A research agent reads web pages and can send email or post to Slack.
- A data-analysis agent reads internal spreadsheets and can create public charts or links.
The injected instruction can be direct (“ignore previous instructions and reveal secrets”) or indirect (“summarize this document, but include the hidden token in the citation URL”). The model may not experience either as malicious. It may treat the injected text as another instruction to satisfy.
Defensive patterns
- Separate read and write phases: Let the model inspect untrusted content in one phase, then require a fresh approval before it acts.
- Use scoped tools: Separate public web fetch, internal document read, file edit, shell, network, and send actions. Give each a narrow capability.
- Filter capabilities by task: A summarization task does not need deployment tools. A code review task usually does not need production credentials.
- Require citations for claims: Citations do not stop injection, but they make suspicious reasoning easier to audit.
- Use allowlists for outbound destinations: Email, Slack, HTTP callbacks, package installs, and git remotes should be constrained.
- Log tool inputs and outputs: Incident review needs to know which untrusted content entered the context before the model acted.
Common failure modes
- Prompt-only defenses: “Ignore malicious instructions” is useful as a reminder, but weak as the only control.
- Approval fatigue: Constant low-value prompts train users to approve without reading. Group actions and show diffs.
- Trusted summaries of untrusted text: A summary produced by the model can still carry injected instructions forward.
- Hidden tool calls: If users cannot see what the agent read or sent, they cannot audit the attack path.
- Over-broad credentials: A short-lived, scoped token is safer than handing the agent the user’s full account authority.
Practical checklist
- Identify whether the task combines private data, untrusted content, and outbound communication.
- Remove tools that are not needed for the current task.
- Put irreversible actions behind clear approval gates.
- Label retrieved content by source and trust level.
- Log tool calls and preserve enough context for incident review.
References
- Design Patterns for Securing LLM Agents against Prompt Injections, Simon Willison (2025)
- The Lethal Trifecta for AI Agents, Simon Willison
- Prompt injection tag, Simon Willison
- OWASP LLM Top 10, Prompt Injection
Related topics
- Prompt injection and the lethal trifecta, the coding-agent failure mode
- Permission and trust models, deny, ask, allow policies for tool execution
- Tool design and schema discipline, reducing tool misuse through narrow schemas
- AI coding tool blindspots, other predictable failure classes