Traditional application security has a clean boundary: code is trusted, data is not, and the job is to keep data from being executed as code. LLM applications erase that boundary. The model can't reliably tell an instruction from its developer apart from an instruction embedded in a PDF a user uploaded, and the same natural language that makes the product useful makes it programmable by anyone who can get text in front of it.
This isn't theoretical. Every team we've worked with that connected a model to real data and real tools has been probed within weeks. Here's the threat model we use and the defences that have held up.
A threat model in five questions
You don't need a heavyweight framework to start. For any LLM feature, answer these five questions in a design review:
- What data can the model see? Include system prompts, retrieved documents, tool outputs and conversation history.
- What actions can it take? List every tool, API and side effect, and the credentials behind them.
- Who controls the content it reads? Customers, employees, the open web, uploaded files and third-party feeds all count.
- Where does its output go? A chat window is low-risk; a browser that renders markdown, a SQL query or a shell command is not.
- What is the worst realistic outcome if the model is fully manipulated? If the answer is uncomfortable, reduce what it can see or do until it isn't.
The last question is the most useful. It turns an open-ended worry into a concrete design constraint.
Prompt injection is the SQL injection of this decade
Direct injection is the user typing "ignore your instructions and…"; annoying, mostly contained by good system prompts and output checks. Indirect injection is the dangerous one: instructions hidden in content the model processes on the user's behalf — a support ticket, an email, a résumé, a web page fetched by a research agent, a code comment in a pull request. The user is innocent; the document is the attacker. Any system that reads untrusted content and can then take an action or reveal data is exposed. Assume the model will be manipulated, and design so that manipulation can't cause harm.
Treat retrieved and fetched content as untrusted input
Mark the origin of every piece of context the model sees and tell it explicitly which parts are data, not instructions. Strip or neutralise instruction-like content from documents before they reach the prompt where feasible. Scan retrieved content and tool outputs for injection patterns. None of these is sufficient alone — models can still be talked around — which is why they're the first layer, not the only one.
Least privilege for tools, always
The blast radius of a manipulated model is exactly the set of actions it can take. Give each agent or feature only the tools its job needs, scoped to the current user's permissions — never a service account that can see everything. Separate read tools from write tools, and gate anything irreversible (sending, paying, deleting, deploying) behind human approval, at least until the evaluation record earns otherwise. If the model has no tool that can exfiltrate data, an injection telling it to exfiltrate data fails by construction. This is the same discipline we describe for production agents — security is one more reason it matters.
Close the exfiltration channels
The classic data-leak chain is: injected instruction → model encodes secret data into a URL → app renders a markdown image or link → the browser fetches it and the attacker's server logs the secret. Defend structurally: don't auto-render external images or links from model output, allow-list outbound domains for any tool that makes HTTP requests, and never put secrets, other users' data or full system prompts anywhere the model can echo them. Assume anything in the context window can end up in the output.
Don't rely on secret prompts, and keep tenants apart
Treat the system prompt as readable. Determined users can often extract it, so never put API keys, credentials or sensitive business logic in it, and don't build security on the assumption that its contents stay hidden. Keep secrets in your backend, where the model never sees them, and let tools authenticate on its behalf with narrowly scoped, short-lived credentials.
In multi-tenant products, enforce isolation outside the model. Filter retrieval by tenant and user permission in the query itself, scope tool calls to the caller's identity, and never rely on an instruction like "only show this customer their own data." A model can be talked out of an instruction; it can't be talked past an access-control check it never controls.
Guard the output, not just the input
Input filters catch the clumsy attacks; output checks catch the rest. Validate model output against a schema before acting on it. Run PII and secret detectors on responses. Verify that any citation or claimed action actually corresponds to retrieved data or a real tool result. For high-stakes flows, use a second, independent model call purely as a checker — a different prompt with a narrow job ("does this response leak data or violate policy?") is much harder to manipulate in the same breath as the first.
Mind the supply chain
An LLM application depends on more than your own code: model providers, prompt templates, plugins, vector databases and increasingly third-party tool servers. Each is a place where trust can be misplaced. Pin model versions where the provider allows it and re-run your tests when they change. Review third-party tools and their descriptions before connecting them, because a malicious or compromised tool can embed instructions in its own metadata or return poisoned output. Read vendor terms on data retention and training use, and keep an inventory of which data flows to which provider.
Red-team before your users do
Build an adversarial test suite alongside your evaluation suite: injection payloads in documents, jailbreak attempts, requests for other users' data, tool-misuse scenarios, and the OWASP Top 10 for LLM Applications as a checklist. Run it in CI on every prompt, model or tool change — a model upgrade can silently change how your app responds to an attack. Then log everything in production: full traces of prompts, retrieved context, tool calls and outputs, so when something does get through you can see exactly how.
Monitor, alert and be ready to respond
Prevention fails eventually, so detection matters. Log full traces, including prompts, retrieved context, tool calls and outputs, with sensible retention and access controls on the logs themselves, since they contain sensitive data. Alert on signals that often precede or accompany abuse: unusual tool-call patterns, spikes in refusals, outputs containing URLs or encoded blobs, requests that probe the system prompt, and sudden jumps in token usage from one account.
Then write the runbook before you need it. Know how to disable a tool or the whole feature quickly, how to revoke credentials the model used, how to identify affected users from your traces and who makes the disclosure call. A kill switch you've tested is worth more than a policy document nobody has opened.
Frequently asked questions
What is prompt injection?
Prompt injection is an attack where text supplied to a model, by the user directly or hidden in content the model processes, overrides or subverts the developer's instructions. Because models treat instructions and data as the same kind of input, it can't be fully eliminated by filtering. The reliable defence is limiting what a manipulated model is able to see and do.
Can guardrails or input filters stop prompt injection completely?
No. Filters and classifiers reduce clumsy attacks and are worth having, but a determined attacker can often rephrase around them. Treat them as one layer alongside least-privilege tools, approval gates for risky actions, output validation and monitoring.
What is the OWASP Top 10 for LLM Applications?
It is a community-maintained list of the most critical security risks for LLM-based systems, covering issues such as prompt injection, sensitive information disclosure, supply-chain vulnerabilities and excessive agency. It is a useful checklist for design reviews and for building a red-team test suite.
How often should we red-team an LLM application?
Continuously for the automated part and periodically for the manual part. Run an adversarial regression suite in CI on every prompt, model or tool change, and schedule deeper manual testing before major launches and after significant new capabilities, particularly new tools or data sources.
The short version
Secure LLM applications assume the model can be manipulated and make sure that manipulation goes nowhere: untrusted content is labelled and filtered, tools are least-privilege and user-scoped, irreversible actions need approval, exfiltration channels are closed structurally, outputs are validated independently, and an adversarial suite runs on every change. Defence in depth isn't a slogan here; it's the only approach that has held.
Shipping an AI feature that touches real data or takes real actions? Talk to us before an attacker does the review for you.