Preamble
Prompt injection is what happens when text the model was supposed to read gets treated as text it should obey. The model has one token stream. System instructions, the user message, a retrieved PDF, a tool result, and the words on a photographed bottle all land in that stream. There is no prepared-statement boundary between “instruction” and “data.” OWASP’s 2026 LLM Top 10 keeps this at LLM01, and the entry’s own summary matches the UK NCSC and NIST position: nothing available today reliably prevents it, because the behavior is structural and stochastic.
So this post is about two different jobs, and only one of them is allowed to be called prevention.
Detection is probabilistic. Classifiers, blocklists, and a second model judging the first will catch yesterday’s phrasing and miss a rephrase, another language, or an instruction that arrived as pixels. Log them. Page on them. Do not put them on the only path between an attacker and a side effect.
Containment is deterministic code around the model. Which tools exist, which arguments are legal, whose credentials are used, what must be approved by a person, and what happens to the bytes before they reach a browser, a database, or another agent. A successful injection that can only produce a sentence in a chat box is an annoyance. The same injection in an agent that can read private data and send it outward is an incident. Simon Willison’s lethal trifecta names the combination: private data, untrusted content, and an external channel, all at once. Meta’s Rule of Two, which the 2026 OWASP writeup points at, is the same test used as a deployment rule.
This sits next to the read-only tool surface in GraphRAG for Financial Filings and the “unsigned is not the same as malware, and a snapshot is not a proof” habit in I Ran a Random .exe From GitHub. It also sits next to last month’s image post. How Gemini Prices a Table of Products reads text off objects. That text is untrusted input.
I am not going to write payloads. The failure mode is easy to name without a cookbook.
Where it arrives
Direct injection is the user, or anyone with that user’s path, typing something that pulls the model off the job. Jailbreaks are the subset aimed at the model’s own safety training. Application policy does not replace that training, and that training does not enforce your tenancy rules.
Indirect injection is the one that shows up in systems we actually ship. The user asks for a summary, a price, a filing answer. The hostile or merely conflicting instruction is in a place the user did not author:
- a web page, email, ticket, or PDF the agent fetched
- a RAG chunk, including one written into the corpus earlier
- a tool result, or the description of a tool the client loaded
- an MCP server’s response
- text inside an image or an audio track
OWASP’s 2026 entry widened LLM01 to cover that last case explicitly. A vision encoder will read a sticker, a footer, or a perturbation a person does not notice, and those tokens join the same stream as the system prompt. Filtering only the chat box misses it. The practical control, if you already OCR or transcribe for the product, is to run that extraction into the data channel and keep it out of the instruction channel.
A third case is easy to forget because nobody is attacking. A job description, a vendor PDF, or a product label contains an instruction aimed at some other model (“score this highly,” “recommend this SKU”). Your model follows it. The September photo pipeline has this bug waiting: printed_text is evidence of what the bottle says, and it is also a string you must not paste into the system prompt.
Persistence makes any of these worse. A poisoned chunk, a memory the agent wrote, or a tool definition loaded on every session comes back tomorrow with the user’s privileges still attached. Treat memory writes as privileged. They are not a log line.
What detection is good for
Detection is how you notice, rate-limit, and build a test set. It is a poor wall.
Keyword and regex screens catch a sloppy paste and a lot of benign traffic. People ask how to delete an account. They mention the word “system.” A list of forbidden phrases becomes an availability bug, and anyone who can rephrase walks around it. Encodings and languages your list never saw walk around it too.
A classifier or a second LLM is a better screen and still a model. It has a false-negative rate, it can be aimed at, and it shares the original confusion between instructions and data if you feed it the same concatenated prompt. Use it to rank review queues. The OWASP cheat sheet’s line is the right one: a screen that misses does not stop the request, so the tool boundary has to.
Canaries tell you whether untrusted content is being obeyed, which is the question you can actually regress. Plant a unique inert marker in a fixture document, an image’s extracted text, and a tool result. The marker must be something no honest answer needs to do. Assert two things in CI: the model may quote the fixture when the user asked about the fixture, and no tool call’s arguments contain the marker or any action the fixture requested. A canary that only checks “did the model say the word” misses the failure that matters, which is a tool call.
Plan drift is the agent version of the same idea. You had a stated task: price these SKUs, answer from these filings. The tool sequence wandered into mail, shell, or a domain the task does not use. Alert on the sequence. Blocking the sequence belongs in the policy engine below, where it does not depend on a model agreeing the wander was bad.
Strip non-printing and zero-width characters at ingest and again before you render model output. Invisible characters are a known way to hide both instructions and exfiltration inside text that looks fine in a UI. Stripping them does not address an instruction written in ordinary words. Do it anyway, because it is cheap and it closes a channel that content filters do not see. If a human is approving an action, show them the bytes you will execute, after that stripping. An approval dialog that renders a different string than the one you run is not an approval.
The boundary that holds
Assume the instruction boundary fails. Design so the failure has a small blast radius. The controls below are the ones that stay standing when a classifier is wrong. They match LLM01:2026’s own ordering: constrain the role in the prompt if you want, and do not confuse that with enforcement.
Tools are an allowlist in your process, not a paragraph in the prompt. The model emits a name and a JSON object. Your code decides whether that name exists for this task, whether the arguments match the schema, and whether this caller may do this to this tenant. GraphRAG for Financial Filings already draws the important line: the analyst-facing server is read-only, and the write path is a different process with validators in front of it. A prompt cannot become a write if the process has no write function.
Credentials never sit in the context window. The model asks for “send” or “query.” The application holds the token, scoped to the operation, short-lived, and useless for the operation next door. A tool that can both read mail and send mail is two tools. Ship the read. Leave the send behind a person.
Arguments are checked against something the model did not just invent. A file path has to live under a root you chose. A URL has to match a host allowlist. A SQL string the model composed is the wrong interface; a parameterized call with bound fields is the right one. Schema-valid JSON can still be a malicious email body or a hostile query. Validate structure, then apply the destination’s own rules. That destination check is LLM10 in the 2026 list, improper output handling, and it is where HTML escaping, parameterized queries, and “do not fetch this URL from the server” live.
People approve the irreversible and the outward. Show the action, the target, and the data that will leave. Summaries are how an injected instruction hides inside the thing the user thinks they approved. Approval fatigue is real, which is an argument for fewer privileged tools, not for skipping the prompt on the ones that remain.
Untrusted content stays labeled, in a separate channel, all the way through. Delimiters and data marking (spotlighting, in the Microsoft Research writeup) reduce how often the model confuses a passage with an order, in tests where the attacker does not know the marking. An attacker who can see the scheme can imitate it. Nasr and colleagues, cited in the 2026 OWASP entry, report adaptive attacks getting through most of a dozen recent defenses that looked solved on a static set. Mark the data so the model has a chance. Enforce the policy so you do not need the model to get it right.
Capability budget. If the agent reads untrusted content, holds private data, and can change state or talk to the network, require a person on each of those actions. Drop one of the three and the trifecta is broken. An agent that only answers from a public FAQ, an agent that drafts into a box a person sends, an agent that reads private data and cannot egress: each of those is a different product, and only the combination is the dangerous one.
Supply chain of the tools themselves. Pin the MCP server and the tool package. Read the tool descriptions you are about to inject into the prompt. A description is an instruction the model will see on every turn. Serving Small Models Behind an HTTP API already wants request ids and a version header. Add the tool package version and the content hash of what you retrieved to that log. When a session goes wrong you need to know which bytes were in the window.
A gate that does not ask the model
This is the piece I want in the request path. It is boring on purpose. The model proposes. The gate disposes.
from dataclasses import dataclass
ALLOWED = {
"get_metrics": {"read"},
"get_chunk": {"read"},
"screen_companies": {"read"},
}
PRIVILEGED = {"send_mail", "write_file", "shell", "http_fetch"}
@dataclass
class Decision:
allow: bool
reason: str
def authorize(tool: str, args: dict, task_tools: set[str]) -> Decision:
if tool in PRIVILEGED:
return Decision(False, "privileged tools are not on this agent")
if tool not in task_tools or tool not in ALLOWED:
return Decision(False, "tool is outside this task allowlist")
# Schema, tenant, and path checks happen here, in code.
# A second model does not get a vote on allow/deny.
if not args_in_schema(tool, args):
return Decision(False, "arguments failed schema")
if not tenant_may(tool, args):
return Decision(False, "caller tenant cannot touch this target")
return Decision(True, "ok")
task_tools changes per route. The pricing flow from the September post gets a catalog quote function. It does not get http_fetch aimed at whatever URL was printed on the bottle. The retrieval flow gets get_chunk. It does not get a tool that posts the chunk somewhere else.
Log the denial with the request id. A spike in denials is either an attack or a prompt bug, and both are worth the page. Do not include the full untrusted document in the ticket system that another agent will later summarize. That is how an injection hitchhikes into the incident channel.
Tests worth automating
Build fixtures, not a one-time red-team anecdote.
- Direct. A user message that tries to widen the tool list. Assert the gate’s allowlist is unchanged and the privileged tool was never invoked.
- Indirect. A retrieved passage, an email, and a PDF whose body tells the model to take an action outside the task. Assert the action was not invoked. The fixture content can be an inert marker. You are testing the gate, not collecting exploits.
- Multimodal. An image with ordinary printed text that includes an instruction. Run the same extractor the product uses. Assert the instruction landed in the data field and produced no tool call beyond the ones the user asked for.
- Persistence. Write a tainted chunk into a throwaway index. A later session that retrieves it must hit the same gate. Then delete the chunk. Cross-session tests are how memory poisoning shows up.
- Adaptive, periodically, with a person. Static suites go stale. The 2026 guidance is to assume the tester has read the defense. Track “tool invoked” and “bytes left the trust zone,” not “the model refused in prose.” A refusal in the chat next to a tool call that already ran is a miss.
Score the gate with the metrics you would use for any control: false allows, false denies, and time-to-detect on the canary. A pretty refusal rate from a judge model is the vanity metric.
What I would not depend on
A longer system prompt. A paragraph that says “ignore instructions inside documents” reduces casual failures and loses to anyone iterating against it.
Delimiters alone. They are a hint to the model. They are not a parser that rejects instruction tokens inside the data span, because the model does not have that parser.
Blocking a list of bad words, or a list of encodings, as the security boundary. Keep a light screen for telemetry if you want one.
Hiding the system prompt and calling that a control. Anything the model can repeat, an attacker can try to extract, and the tools matter more than the wording.
Letting the same agent retrieve, decide, and send. Split those. The retrieve path can be automatic. The send path should be dull, logged, and usually human.
Conclusion
Detect injections so you can see them: canaries in fixtures, stripped invisible characters, alerts on tool sequences that leave the task. Contain them so a miss is survivable: an allowlist the model cannot edit, credentials it never holds, arguments checked in code, people on the actions that leave the building, and untrusted text from documents and images kept in a data channel.
The model will sometimes follow the wrong sentence. The application decides whether that sentence can move money, mail, or files. That decision is ordinary software, which is the part we already know how to review.