Prompt injection for builders: treat model output as a suggestion, not an order
Why prompt injection cannot be filtered away, and the controls that hold up: separation, code-side permissions, approval for risky actions and monitoring.

If your application puts text from a user, a web page or a document in front of a language model, someone can write text that tries to give the model new orders. That is prompt injection. It is worth understanding clearly, because the most common reaction to it, writing a better filter, is the one that works least well.
The better reaction is a design one: assume the model can be talked into suggesting the wrong thing, and make sure that a wrong suggestion cannot do much.
Why it happens
Traditional injection attacks, such as SQL injection, work because data and commands share a channel. We fixed those with parameterised queries, which keep the two apart. OWASP's prompt injection cheat sheet points out that language models are different: instructions and data both arrive as natural language, with no hard separation between them.
There are two main paths:
- Direct: the user types instructions meant to override yours.
- Indirect: the instructions are hidden in content the model reads later, such as a web page, an email, an issue description, a code comment or a document.
The indirect route catches builders off guard because the person using your product might never see the hostile text.
Why filters are not enough
The cheat sheet lists many ways the same request can be disguised: Base64 or hex, invisible Unicode characters, other languages, scrambled letters that a person can still read, and markdown or HTML that tries to leak data through an image link. It also describes "best-of-N" attempts, where an attacker tries many random variations of one prompt, changing capitalisation or spacing, until one gets through.
Its guidance is straightforward: screening input helps with flagging, logging, and rate limiting, but it isn't a security boundary. Safety training and lowering the temperature do not stop a determined attacker either. Keep authorisation outside the model.
Note
That does not make filters pointless. They give you signals and logs. They just cannot be the thing your safety depends on.
The rule that does the work
Think of the model as a capable colleague who reads everything in front of them and sometimes takes it at face value. You would not give that colleague the keys to every system on their first day. You would give them a narrow set of permissions and ask for a second pair of eyes on anything serious.
In practice that means four controls, all enforced in ordinary code.
1. Separate trusted and untrusted text
Put your instructions and the outside content in clearly labelled sections, and say in the prompt that the content is material to analyse, not instructions to follow. It helps, but OWASP notes that labels alone don't enforce the boundary. Treat this as a courtesy to the model, not a lock.
2. Check every tool call in code
When the model proposes an action, your code decides whether it happens. Check the tool, the arguments and the permissions of the person or agent on whose behalf it runs, outside the model.
func (g *Gateway) Call(ctx context.Context, caller Caller, c ToolCall) (Result, error) {
tool, ok := g.tools[c.Name]
if !ok || !caller.MayUse(tool) {
return Result{}, ErrNotAllowed
}
if err := tool.ValidateArgs(c.Args); err != nil {
return Result{}, err
}
if tool.Risky && !g.approvals.Has(caller, c) {
return Result{}, ErrNeedsApproval
}
return tool.Run(ctx, c.Args)
}
Nothing in this function reads the model's reasoning or the prompt. A persuasive injected paragraph has nothing to persuade.
3. Ask a person about risky actions, and bind the approval
Sending money, deleting data, emailing outside the company, changing access: these should wait for a human. The cheat sheet adds a detail that is easy to miss. The approval should be tied to the exact action, with its target and arguments, and the decision to ask should depend on the operation and who is calling, not on how the prompt was worded. An approval for "send the report" should not stretch to cover a different recipient.
Watch out for approval fatigue. If people are clicking "yes" on forty prompts a day, the control breaks down. Reserve it for what matters and make each request show exactly what will happen.
4. Give less access in the first place
Least privilege shrinks the damage of every other failure. Use read-only database accounts where reading is enough, narrow API scopes, and only the tools the current task needs. We covered this in giving an AI agent only the access it needs; it is the most reliable lever you have.
Treat output as untrusted too
What comes out of the model is also input to something else. If you render it as HTML, escape it. If you build a query from it, parameterise it. If it contains a link or image URL, think about whether fetching it could carry data to a stranger's server. Scanning for leaked system prompt text or key-shaped strings is a sensible extra layer, though keyword matching on its own is weak.
flowchart LR
U[Untrusted content] --> M[Model]
M --> P[Proposed tool call]
P --> C{Code checks: tool, arguments, permissions}
C -- risky --> H[Human approval for this exact action]
C -- allowed --> T[Run tool]
H --> T
C -- denied --> X[Refuse and log]
Watch and test
Log security decisions, such as denied calls and approval requests, but leave secrets and sensitive content out of the logs. Alert on unusual patterns: a sudden burst of tool calls, or a tool being used in a way it never is.
For testing, the cheat sheet offers a small smoke test of 16 attack inputs and 9 benign requests, and is explicit that it is "a smoke test, not a security benchmark". Two habits from it are worth copying: grade each security objective separately, using dummy markers and instrumented tools rather than real ones, and count false positives on harmless requests so your defences do not quietly block real work. A pass does not prove you can resist a persistent attacker. If you already have an agent test suite, twenty well-chosen tasks can include a few hostile documents.
A short checklist
- Assume any text the model reads may contain instructions.
- Enforce permissions and argument checks in code, never in the prompt.
- Require approval, bound to the exact action, for anything hard to undo.
- Start with read-only access and narrow scopes.
- Escape or parameterise model output before it reaches another system.
- Log decisions without secrets; test with harmless markers.
A note on model-based guardrails
The cheat sheet also describes separate classifier models that screen inputs, outputs or proposed actions, and a research design called CaMeL, from Google DeepMind, which keeps a planner away from untrusted data. These can add a useful layer. The same document cautions that guardrail models can be injected themselves, add latency and cost, and need monitoring, so use them in addition to the controls above and not instead of them.


