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.

TopicsAI Agents and AutomationGenerative AI and LLMs

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.

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.

SurfaceExamplesTypical injection routeWorst plausible outcome
Inbound contentEmails, tickets, uploaded files, chat messagesHidden instructions in body text, metadata or imagesAgent takes actions the sender wanted, not the user
Retrieved contentWeb pages, knowledge base articles, RAG documentsPoisoned page or document in the indexMisleading answers; instructions executed at retrieval time
Tool resultsAPI responses, search results, database rows containing user textAttacker-controlled fields returned by a trusted toolChained actions across systems
Tool definitionsThird-party MCP servers, pluginsMalicious or changed tool descriptionsAgent misuses tools or leaks arguments
Output channelsEmail, webhooks, links, images, file writesData encoded into URLs or messagesExfiltration of private data
MemoryLong-term notes, conversation summariesInjected instruction persisted for later sessionsDelayed, repeated compromise

Questions to answer per agent

  1. Which inputs can an outsider influence, even indirectly?
  2. What is the most damaging action any connected tool can take?
  3. Whose credentials does each tool use: the end user’s, a service account or an admin key?
  4. Can the agent send data anywhere an attacker could read it?
  5. 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.

PatternWhat it doesStrengthCost and trade-offs
System prompt hardeningTells the model its role and to ignore conflicting instructionsWeak: easily bypassedCheap; still worth doing
Labelling untrusted contentWraps external text with clear delimiters and provenanceWeak to moderateCheap; reduces accidental injection
Input and output classifiersDetects likely injections and sensitive data in outputsModerate: probabilisticAdds latency and false positives
Deterministic output validationChecks structured outputs against schemas and allowlists in codeStrong for the actions it coversRequires typed tool interfaces
Least-privilege tools and credentialsLimits what any tool call can do, regardless of model intentStrongMore design work; narrower tools
Human approval for consequential actionsPuts a person in front of irreversible or external actionsStrong if approvals are meaningfulSlower; risk of rubber-stamping
Plan and data separationFixes the action plan from trusted input before reading untrusted dataStrongest availableReduces 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 profileExampleMinimum controls
Read-only, internal data only, trusted inputsPolicy Q&A over an internal handbookPrompt hardening, access-scoped retrieval, logging
Reads untrusted content, no write toolsSummarising inbound supplier emailsAbove, plus output channel restrictions (no links or images to external hosts), classifiers
Write tools on internal systemsUpdating ticket fields or CRM notesAbove, plus typed tools, schema validation, user-scoped credentials, approval for bulk or destructive changes
External actions or money movementSending customer emails, issuing refundsAbove, plus human approval per action, allowlists, plan and data separation, transaction limits
All three trifecta capabilitiesBrowsing agent with inbox access and send rightsRedesign: 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Separate untrusted processing. Route external content through a step without tool access that returns structured fields, and validate those fields in code.
  6. Add approval gates. Require human confirmation for external communication, payments, deletions, permission changes and bulk updates.
  7. Bound execution. Set step limits, timeouts, spend caps and per-tool rate limits so a manipulated agent cannot loop indefinitely.
  8. Log everything. Record prompts, retrieved sources, tool calls with arguments, approvals and outputs, linked by a trace ID.
  9. 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

  1. Each agent’s trifecta exposure is documented, and no single agent context combines all three without a compensating design.
  2. Tools are narrow, typed and validated server-side; no raw SQL, shell or arbitrary HTTP tools in production.
  3. Credentials are scoped to the end user and to minimum permissions.
  4. Retrieval respects the user’s access rights.
  5. External links and images in output are blocked or allowlisted.
  6. Outbound recipients and domains are allowlisted.
  7. Consequential actions require meaningful human approval.
  8. Untrusted content is processed in a step that cannot call tools.
  9. Step limits, timeouts, rate limits and spend caps are configured.
  10. Every prompt, retrieval, tool call and approval is logged with a trace ID.
  11. An injection test suite runs in CI on every model, prompt or tool change.
  12. Third-party tool servers are reviewed and pinned to known versions.
  13. 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.

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.