Prevent Prompt Injection
- Source
- openrouter.ai
- Author
- OpenRouter editorial sitemap
- Date

Context
In a test it ran on its own tools, OpenRouter, the service that sends API requests to models from many providers, found that the defense that reliably stopped a document from steering an checked the agent's actions before they ran, instead of trusting the model to ignore the attack. The threat is indirect : text inside a document, email or web page an app reads that addresses the model as if it came from the user. A model that can only reply can at worst say something wrong or reveal its prompt. An agent with tools can act on the stranger's request, for example by emailing data to an outside address. OpenRouter's write-up is a tutorial for its own products, so its numbers come from one controlled setup rather than an independent audit.
The test assistant, called DocBot, summarized documents, held a made-up secret code in its instructions and had a send_email tool. OpenRouter ran it on four models: Claude Haiku 5.5, GPT-6 Luna, DeepSeek V4.1 Flash and Z.ai's GLM 5.3 Flash. The attacks were 13 OpenRouter wrote and 12 written by two other models that never saw the defenses. Without defenses, three of the models resisted almost everything, while GLM 5.3 Flash sent 58 of the 60 attack emails across 720 attempts. The attack that worked best contained no suspicious phrases: it was a note in the document's own voice, presented as a routine processing step, asking for a receipt email to an outside address.
The cheap defenses reduced the odds without removing them. Wrapping each document in tags with a random name per request, and telling the model that tagged text is never an instruction, cut attack emails from 60 to 13 of 720 and blocked no legitimate email. The model still decides whether to obey, though, and all 13 came from GLM 5.3 Flash. OpenRouter's then limit what a key can reach: a model keeps an app off models that failed this kind of test, and a spending cap bounds the cost of a runaway agent.
The control that held was Armor, an OpenRouter feature in beta that sends every tool call, with the conversation and rules written in plain English, to a separate decision model before the call reaches the developer's code. A hard-deny rule can never be cleared, such as never emailing the secret. A soft-deny rule blocks an action unless the user asked for that exact action, which is how it separates a user's request from a document's. With Armor on, attack emails fell to 0 of 720, with or without the tags, and all 160 legitimate emails still went out. On responses that called a tool, the median request took 3.65 seconds with Armor against 3.37 without, and the Armor documentation covers the rule format and an audit mode that records verdicts without blocking.
Armor blocked real work in one pattern. When a user said the document's process note was real and asked DocBot to send that receipt too, without naming the address, Armor blocked 55 of 80 attempts; when the user named the address, it blocked none. On the Chat Completions API, Armor's default places a marker for the blocked call in the reply, and in 19 of the 73 blocked calls that marker contained the secret code, so it has to be stripped before the reply is shown or stored. The article's simpler advice still applies to any setup: keep real secrets out of the prompt, and require a person's approval for actions that cannot be undone.
- OpenRouter advises wrapping untrusted content in a tag with a random name generated per request, because with a fixed tag like <document> an attacker can write the closing tag inside the document and place their own text outside it.
- In OpenRouter's tests, the best-working outside-written attack had no injection keywords or encoding: a 'process note' asking for a receipt email in the document's own voice. GLM 5.3 Flash sent 58 of the 60 attack emails, which OpenRouter cites to argue for a model allowlist.
- OpenRouter's Armor has two rule types: a hard_deny rule can never be cleared, even if the user asks, while a soft_deny rule blocks a tool call unless the user asked for that exact operation on that exact target. That is how it separates user requests from injections.
- Armor blocked 55 of 80 legitimate sends when the user approved a document's instruction without naming the recipient, but none when the user named the address. OpenRouter measured median latency on tool-calling responses at 3.65 seconds with Armor versus 3.37 without.
- On the Chat Completions API, Armor's default text mode puts a blocked call into the reply as a marker, and in 19 of OpenRouter's 73 blocked calls that marker contained the secret. OpenRouter says to strip it before showing or storing replies, and to start new rules in audit mode.
- AI agent — An AI system that doesn't just answer once but works toward a goal in a loop — taking actions, reading the results, and deciding what to do next.
- prompt injection — An attack that hides instructions in content an AI will read — a webpage, email, or document — tricking it into following the attacker instead of the user.
- guardrails — The checks around a model that block bad inputs and outputs — filters, validators, and permission rules the model itself can't override.
- tool permissions — The rules governing which tools an agent may call and which need confirmation — the boundary between a mistake and an incident.
Checking sign-in…
Loading comments…






