Book a 30-min callBook a call

Prompt injection defenses: what works, what doesn't, and design patterns for agents

Prompt injection defenses compared: classifiers, spotlighting, instruction hierarchy, dual LLM, CaMeL, plan-then-execute, least privilege and testing.

A user card feeding a planner circle, an untrusted document behind a wall feeding a separate quarantined circle, and the planner alone connected to a row of tool cards.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
16 min read

Questions people ask

Can a system prompt stop prompt injection?

No. A system prompt is text, and prompt injection works because other text can override it. Models trained on an instruction hierarchy give the system prompt more weight, which helps, but the protection that holds comes from outside the model: limits on which tools run, with which arguments, and human confirmation for consequential actions.

Is indirect prompt injection more dangerous than direct injection?

For agents, usually yes. Direct injection comes from the user, whose access the application already limits. Indirect injection arrives in web pages, emails, files and tool results, written by anyone, and acts with the user's access. An agent that reads the open web or a shared inbox should assume some of what it reads is hostile.

Does spotlighting or datamarking solve prompt injection?

It lowers the attack success rate, by a large margin in the authors' experiments, at little cost to the task. It does not solve it, because the model still decides whether to obey marked text. Use it as one layer, with a random marker per call, under architectural limits on what the agent can do.

What is the lethal trifecta?

Simon Willison's name for the combination that makes an agent leak: access to private data, exposure to untrusted content, and a way to communicate externally. With all three, an injected instruction can read the data and send it out. Removing any one leg removes that path.

How do I test my agent for prompt injection?

Start with a public benchmark such as AgentDojo to compare defenses, measuring both task success under attack and attack success. Then build a suite for your own agent: injections planted in the data your tools actually return, adaptive attacks written with knowledge of your prompts, and every past incident. Run it on each change of model, prompt or tool.

Building something like this?