Treat the model as an untrusted user
A language model reads instructions and data in the same stream of text and has no reliable way to tell them apart. Anyone who can put text in front of it, whether a customer, an email sender or the author of a web page, can try to steer it. So the useful design question is not 'how do we stop the model being fooled?' but 'what could it do if it were?'
The answer should be: nothing the current user could not do anyway. Authorisation is enforced in code, inside the tools, against the real user's identity. The model asks; the tool layer decides. A security rule that exists only in the system prompt is a suggestion, not a control.
Prompt injection, direct and indirect
Prompt injection is direct when a user types instructions to override the rules, and indirect when the instructions hide in content the agent reads: an email, a support ticket, a PDF, a product review, a calendar invite, text inside an image or the description of a tool. Indirect injection is the more dangerous kind, because the person harmed is not the person who wrote the attack.
Imagine an assistant that summarises a shared inbox and can send email. A message arrives with hidden text telling it to forward the latest invoices to an outside address. If one agent can read private data, reads untrusted content and can send data out, the attack has everything it needs. Break that combination for each task:
- Give the step that reads untrusted content no access to private data or outbound tools.
- Allow outbound actions only to approved destinations, or only after a person approves them.
- Keep untrusted content away from the steps that plan actions, and label it as data when it must be passed on, knowing that a label alone does not stop an attack.
The OWASP Top 10 for LLM Applications
The OWASP Top 10 for LLM Applications (2025 edition) is the usual checklist, a sibling of the OWASP Top 10 for web applications. This is what we check for each risk:
| Risk | What we check |
|---|---|
| Prompt injection | Direct and indirect attacks through every input the model reads |
| Sensitive information disclosure | Whether replies, logs or errors reveal personal data, secrets or other users' records |
| Supply chain | Where models, datasets, plugins and tool servers come from, and who can change them |
| Data and model poisoning | Who can add to training data, fine-tuning sets and the documents the agent retrieves |
| Improper output handling | Whether model output reaches a browser, database, shell or URL fetcher without escaping or validation |
| Excessive agency | Tools, permissions and autonomy beyond what the task needs |
| System prompt leakage | Secrets or security rules placed in the prompt, which should be assumed readable |
| Vector and embedding weaknesses | Document-level permissions in the index, and leakage between customers |
| Misinformation | Ungrounded answers people may act on, and how the interface shows uncertainty |
| Unbounded consumption | Rate limits, step limits and spending caps that stop abuse and runaway cost |
Excessive agency and unsafe tool use
The damage an attack can do is set by what the agent is allowed to do. Keep that small:
- Narrow tools. 'Look up this order for this customer' rather than 'run any database query'. Each tool does one job with typed arguments.
- The user's permissions, not a master key. The agent acts with the signed-in user's rights through scoped, short-lived credentials, following least privilege.
- Checks in the tool, not the prompt. The tool confirms that the order belongs to this customer and the amount is within the limit, whatever the model asked for.
- Read before write. Start agents read-only, add write actions one at a time, and have a person approve the irreversible ones.
- Third-party tool servers. A Model Context Protocol server or plugin is code running with your permissions, and the model reads its tool descriptions, so a malicious one can carry instructions. Review and pin them like any dependency.
Data leakage and secrets
- Retrieval permissions. If the index ignores document permissions, any user can retrieve the HR file by asking the right question. Filter by the user's access at query time.
- Customer separation. Caches, conversation memory and indexes must never mix one customer's data with another's.
- Secrets out of reach. API keys live in a secrets manager, and only the tool layer uses them. The model never sees them, so it cannot reveal them.
- Exfiltration through the interface. An injected instruction can make the model write an image link whose address carries private data; when the chat renders it, the browser sends the data away. Do not render images or links to unapproved domains, and set a content security policy.
- Provider settings. Check how your model provider retains and uses prompts and outputs, and choose the settings your data rules require.
Model output is untrusted input
Whatever the model writes becomes input to something else, so handle it like text from a stranger. Escape it before it reaches a page, or you have cross-site scripting. Never build a database query or shell command from it; pass values as parameters to fixed operations. If the agent fetches URLs, restrict the hosts it may reach so it cannot be pointed at internal systems. If it runs code, run it in a sandbox with no network access and no secrets. Validate structured output against a schema and reject anything that does not fit.
How we test an LLM application
- Threat model first. Map what the system reads, what it can do and who can put text in front of it, as in our threat modelling practice.
- Injection suites. Direct attacks, plus indirect ones planted in the documents, emails and web pages the agent will read.
- Permission tests. Two test accounts in separate organisations, each trying to reach the other's data through the agent.
- Exfiltration and output tests. Attempts to leak data through links, images, tool calls and rendered markup.
- Abuse and cost. Floods, very long inputs and loops that test rate limits and spending caps.
- Report and retest. Findings with severity, evidence and a specific fix, then a retest. The attack cases join the regression suite described in AI agent testing.
The AI layer sits on an ordinary web application and API, which still need penetration testing and secure code review. Both are part of our cybersecurity service, and our security checklist for AI agents is a short version to work through.
No test proves that an AI application cannot be manipulated. It shows which attacks failed within the time and scope agreed, so the design must limit the damage of the attacks nobody tried.