Home / Insights / AI Agents and Automation
AI Agents and Automation
Prompt Injection in Agentic Systems: Protecting Tools, Data and Actions
Once an AI agent can read untrusted content and call tools, prompt injection stops being a chatbot embarrassment and becomes a route to data theft and unauthorised actions. The defence is architectural: limit what injected text can reach, not just what the model is told.
Key takeaways
- OWASP states there is no known foolproof prevention for prompt injection, so agent security must assume the model will sometimes follow injected instructions.
- The highest-risk design combines private data, untrusted content and a way to send data out; remove at least one of the three from any single agent context.
- Enforce permissions in code at the tool layer: scoped credentials, typed inputs, allowlists and human approval for consequential actions.
- Separate planning from untrusted data where you can, so content an agent reads can inform answers but cannot change which actions it takes.
- Test agents adversarially before and after every change, and log every tool call so an incident can be reconstructed.
On this page
- How prompt injection works once an agent has tools
- Mapping your agent’s attack surface
- Defensive patterns, from weakest to strongest
- How to decide which controls each agent needs
- Implementing the controls: a step-by-step build plan
- Testing, monitoring and incident response
- Prompt injection control checklist
- Frequently asked questions
- Sources and methodology
A customer service agent that reads incoming emails, a procurement agent that browses supplier websites, a coding agent that opens pull requests: each of these is useful precisely because it reads content you do not control and then acts. That combination is what makes prompt injection a serious security problem rather than a curiosity. An attacker no longer needs access to your systems. They need only to place text where your agent will read it.
This article is for CTOs, security leads and product owners who are putting AI agents into production and need to decide which controls are essential. It explains how prompt injection works in agentic systems, which architectures are most exposed, the defensive patterns that actually reduce risk, and how to test and operate them. When PoliteTech designs AI agents, agents receive only the tools they need with explicit permissions, write actions usually require human approval, tools have typed inputs, validation and rate limits, and every action is logged. The reasoning behind those defaults is set out below.
How prompt injection works once an agent has tools
The OWASP Top 10 for LLM Applications lists prompt injection as LLM01 and defines it as input that alters a model’s behaviour or output in unintended ways. Importantly, OWASP notes that injected content does not need to be visible to a human, only parsed by the model, and that no foolproof prevention is currently known because of how generative models work.
Direct and indirect injection
- Direct injection comes from the user typing into the agent, for example asking it to ignore its rules and query private records.
- Indirect injection arrives inside content the agent processes: a web page, a PDF attachment, a support ticket, a calendar invite, a code comment or a tool result. This is the dangerous variant for agents, because the person using the agent is usually the victim, not the attacker.
Why agents raise the stakes
For a plain chatbot, a successful injection mostly produces embarrassing text. OWASP’s list of impacts includes unauthorised access to functions available to the model, arbitrary command execution in connected systems and manipulation of critical decisions. Each tool you connect expands that list. An agent that can send email can be persuaded to send email; an agent that can update a CRM record can be persuaded to change one.
The lethal trifecta
Simon Willison’s widely cited framing, published in June 2025, identifies three capabilities that together enable data theft: access to private data, exposure to untrusted content, and the ability to communicate externally. Models follow instructions wherever they appear and cannot reliably tell an operator’s instructions from an attacker’s, so an agent with all three can be told to read something private and send it somewhere public. Even rendering a markdown image link can be an exfiltration channel. He also points out that guardrail products advertising detection of 95% of attacks would be a failing grade in web security.
Action for this section
For every agent you run or plan, write down which of the three trifecta capabilities it has. Any agent with all three is your first remediation target.
Mapping your agent’s attack surface
Generic AI risk registers are too vague to drive engineering decisions. Threat-model each agent around its inputs, tools and outputs.
| Surface | Examples | Typical injection route | Worst plausible outcome |
|---|---|---|---|
| Inbound content | Emails, tickets, uploaded files, chat messages | Hidden instructions in body text, metadata or images | Agent takes actions the sender wanted, not the user |
| Retrieved content | Web pages, knowledge base articles, RAG documents | Poisoned page or document in the index | Misleading answers; instructions executed at retrieval time |
| Tool results | API responses, search results, database rows containing user text | Attacker-controlled fields returned by a trusted tool | Chained actions across systems |
| Tool definitions | Third-party MCP servers, plugins | Malicious or changed tool descriptions | Agent misuses tools or leaks arguments |
| Output channels | Email, webhooks, links, images, file writes | Data encoded into URLs or messages | Exfiltration of private data |
| Memory | Long-term notes, conversation summaries | Injected instruction persisted for later sessions | Delayed, repeated compromise |
Questions to answer per agent
- Which inputs can an outsider influence, even indirectly?
- What is the most damaging action any connected tool can take?
- Whose credentials does each tool use: the end user’s, a service account or an admin key?
- Can the agent send data anywhere an attacker could read it?
- Does anything the agent writes persist into future sessions?
If you have adopted MCP to connect tools, the security picture includes the servers themselves. We covered the integration side in agent interoperability standards (MCP and A2A); treat any third-party tool server as untrusted code until reviewed.
Defensive patterns, from weakest to strongest
Defences fall into three layers: prompt-level, filter-level and architectural. Prompt-level measures help a little; architectural measures are what limit damage when, not if, an injection succeeds.
| Pattern | What it does | Strength | Cost and trade-offs |
|---|---|---|---|
| System prompt hardening | Tells the model its role and to ignore conflicting instructions | Weak: easily bypassed | Cheap; still worth doing |
| Labelling untrusted content | Wraps external text with clear delimiters and provenance | Weak to moderate | Cheap; reduces accidental injection |
| Input and output classifiers | Detects likely injections and sensitive data in outputs | Moderate: probabilistic | Adds latency and false positives |
| Deterministic output validation | Checks structured outputs against schemas and allowlists in code | Strong for the actions it covers | Requires typed tool interfaces |
| Least-privilege tools and credentials | Limits what any tool call can do, regardless of model intent | Strong | More design work; narrower tools |
| Human approval for consequential actions | Puts a person in front of irreversible or external actions | Strong if approvals are meaningful | Slower; risk of rubber-stamping |
| Plan and data separation | Fixes the action plan from trusted input before reading untrusted data | Strongest available | Reduces flexibility; more engineering |
Least privilege, enforced in code
OWASP’s mitigations include giving the application its own scoped API tokens, handling privileged functions in code rather than through the model, and requiring human approval for high-risk actions. In practice that means narrow tools (get_order_status(order_id) rather than run_sql(query)), credentials scoped to the end user rather than an admin, allowlisted recipients and domains for any outbound call, and rate limits. The MCP security best practices take the same line for tool servers: request minimal scopes, elevate incrementally, and never pass through tokens that were not issued for that server.
Separate planning from untrusted data
The most promising research direction treats the model as untrusted. Google researchers’ CaMeL paper, Defeating Prompt Injections by Design (2025), extracts the control and data flow from the trusted user query so that untrusted data retrieved later can never change the program flow, and uses capabilities to block unauthorised data flows at tool-call time. On the AgentDojo benchmark it solved 77% of tasks with provable security, against 84% for an undefended system. That gap is the honest price of strong guarantees, and for many business workflows it is worth paying.
You do not need to implement CaMeL to use the idea. A simpler version: a planner sees only the user’s request and produces a fixed list of permitted tool calls; a separate, tool-less step reads untrusted documents and returns structured data; code then executes the plan with that data. Injected text can corrupt the data, but cannot add a new action.
How to decide which controls each agent needs
Not every agent needs the strongest pattern. Match controls to the consequences of a successful injection.
| Agent profile | Example | Minimum controls |
|---|---|---|
| Read-only, internal data only, trusted inputs | Policy Q&A over an internal handbook | Prompt hardening, access-scoped retrieval, logging |
| Reads untrusted content, no write tools | Summarising inbound supplier emails | Above, plus output channel restrictions (no links or images to external hosts), classifiers |
| Write tools on internal systems | Updating ticket fields or CRM notes | Above, plus typed tools, schema validation, user-scoped credentials, approval for bulk or destructive changes |
| External actions or money movement | Sending customer emails, issuing refunds | Above, plus human approval per action, allowlists, plan and data separation, transaction limits |
| All three trifecta capabilities | Browsing agent with inbox access and send rights | Redesign: split into separate agents or remove a capability |
For example, a recruitment firm might want an agent that reads CVs, checks them against a role and emails candidates. CVs are untrusted content, candidate data is private, and email is an external channel. A safer design has the agent produce a shortlist and draft messages into an approval queue, with a recruiter sending them. The example is illustrative, but the pattern of converting an external action into a reviewed draft applies widely.
Make approvals meaningful
An approval screen that shows “Agent wants to send an email. Approve?” invites rubber-stamping. Show the exact recipient, full content, the source documents that influenced it and anything unusual, such as a recipient outside the usual domain. Our article on customer support AI agent architecture covers escalation design in more depth.
Implementing the controls: a step-by-step build plan
- Inventory tools and data. List every tool, its credentials, the data it can read and the actions it can take. Remove anything the workflow does not need.
- Redesign tools to be narrow and typed. Replace generic tools (raw SQL, arbitrary HTTP, shell) with task-specific functions with validated parameters and server-side permission checks.
- Scope credentials to the user. The agent should never be able to see or change more than the person it acts for. Retrieval must respect the same access rules.
- Close exfiltration channels. Block rendering of external images and links in agent output by default, allowlist outbound domains and recipients, and strip URLs from tool arguments that do not need them.
- Separate untrusted processing. Route external content through a step without tool access that returns structured fields, and validate those fields in code.
- Add approval gates. Require human confirmation for external communication, payments, deletions, permission changes and bulk updates.
- Bound execution. Set step limits, timeouts, spend caps and per-tool rate limits so a manipulated agent cannot loop indefinitely.
- Log everything. Record prompts, retrieved sources, tool calls with arguments, approvals and outputs, linked by a trace ID.
- Test adversarially. Build an injection test suite (see below) and run it in CI on every prompt, model or tool change.
These steps complement general LLM application security. If your team has not yet worked through the wider risk list, our walkthrough of the OWASP Top 10 for LLMs is a good companion, as is our guide to input filtering, output checks and policy enforcement.
Testing, monitoring and incident response
Build an injection test suite
OWASP recommends regular adversarial testing that treats the model as an untrusted user. Its example scenarios are a useful starting catalogue: hidden instructions in web pages, poisoned RAG documents, payloads split across a document, instructions hidden in images, and obfuscation through other languages or encodings such as Base64. For each agent, write test cases that:
- Plant instructions in every untrusted input channel the agent reads.
- Attempt to invoke each write tool with attacker-chosen arguments.
- Attempt to exfiltrate a canary value through links, images, emails and tool arguments.
- Attempt to persist an instruction into memory for later sessions.
Measure the outcome at the tool layer: did a disallowed tool call execute, or did the canary leave the system? Whether the model “refused” in text matters less than whether the action happened.
Monitor in production
- Alert on tool calls that fail validation or permission checks; they are often attempted injections.
- Track approval rejection rates; a spike suggests the agent is being steered.
- Watch for outbound requests to new domains and unusual argument patterns.
Prepare for incidents
Have a kill switch per agent and per tool, a way to revoke the agent’s credentials quickly, and a runbook to reconstruct a session from logs. Because model behaviour is non-deterministic, an attack may succeed only occasionally, so log retention needs to cover the period in which a report might arrive.
Prompt injection control checklist
- Each agent’s trifecta exposure is documented, and no single agent context combines all three without a compensating design.
- Tools are narrow, typed and validated server-side; no raw SQL, shell or arbitrary HTTP tools in production.
- Credentials are scoped to the end user and to minimum permissions.
- Retrieval respects the user’s access rights.
- External links and images in output are blocked or allowlisted.
- Outbound recipients and domains are allowlisted.
- Consequential actions require meaningful human approval.
- Untrusted content is processed in a step that cannot call tools.
- Step limits, timeouts, rate limits and spend caps are configured.
- Every prompt, retrieval, tool call and approval is logged with a trace ID.
- An injection test suite runs in CI on every model, prompt or tool change.
- Third-party tool servers are reviewed and pinned to known versions.
- Kill switches and credential revocation are tested.
If more than three items are open on an agent that already has write access, reduce its permissions until they are closed.
Frequently asked questions
Can a better model or a stronger system prompt solve prompt injection?
No. Newer models resist some attacks better, but OWASP states no foolproof prevention is known. Treat model-level resistance as one layer and rely on tool permissions, approvals and data-flow separation to limit damage.
Are prompt injection detection tools worth buying?
They can reduce noise and catch common attacks, so they are a reasonable layer. They are probabilistic, though, and should never be the control that stands between an attacker and a consequential action.
Is retrieval-augmented generation (RAG) affected?
Yes. Any document in the index can carry instructions, and OWASP lists poisoned RAG documents as an example scenario. Control who can add content, label retrieved text as untrusted and keep retrieval-only steps away from write tools.
Does human approval slow everything down?
It adds a step for consequential actions only. Most agents spend most of their time reading, classifying and drafting, which need no approval. Well-designed approval screens take seconds and catch exactly the cases that matter.
What should we ask a vendor about prompt injection?
Ask how tool permissions are enforced outside the model, which actions require approval, how untrusted content is isolated, whether exfiltration channels are restricted, what adversarial tests they run and what is logged for incident response.
Do MCP tool servers introduce extra risk?
They can. Tool descriptions and results are more content the model reads, and servers may hold powerful credentials. Follow the MCP security guidance on minimal scopes and token handling, and review third-party servers before connecting them.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- OWASP GenAI Security Project: LLM01:2025 Prompt Injection — accessed 9 November 2026. Supports the definition of direct and indirect injection, impacts, the absence of foolproof prevention, the mitigation list and example attack scenarios.
- Simon Willison: The lethal trifecta for AI agents (June 2025) — accessed 9 November 2026. Supports the private data, untrusted content and external communication framing, and the limits of probabilistic guardrails.
- Debenedetti et al.: Defeating Prompt Injections by Design (arXiv, 2025) — accessed 9 November 2026. Supports the control-flow and data-flow separation approach, capability-based policies and the 77% versus 84% AgentDojo results.
- Model Context Protocol: Security Best Practices — accessed 9 November 2026. Supports least-privilege scope design, incremental elevation and the prohibition on token passthrough for tool servers.
Related reading
Continue your research
Could untrusted content steer one of your AI agents today?
We can threat-model your agents, redesign tools and permissions around least privilege, and build an injection test suite into your release pipeline.
