---
title: How do you stop prompt injection that arrives through tool outputs?
url: https://opencontroller.lyzr.com/blog/stop-prompt-injection-through-tool-outputs
published: 2026-11-12
updated: 2026-11-12
author: Lyzr
---

# How do you stop prompt injection that arrives through tool outputs?

**You cannot filter it out completely, so design the agent so that injected text cannot do much damage. The strongest defences are architectural: limit what an agent that reads untrusted content is allowed to do, separate planning from untrusted data, and restrict where data can be sent. Detection classifiers and prompt hardening help, but they lower the success rate rather than remove the risk.**

Indirect prompt injection happens when an agent reads content it did not write, such as a web page, an email, a support ticket or a file, and that content contains instructions. The agent treats the instructions as part of its task. Every tool that returns external text is a delivery route, including MCP tools.

## Why is tool output so risky?

A model sees one stream of tokens. It has no reliable built-in way to tell "instructions from my operator" from "text a tool returned". OWASP lists prompt injection as LLM01 in its 2025 Top 10 for LLM Applications and treats indirect injection as a core form of it.

Risk peaks when one agent combines three things, a pattern often called the "lethal trifecta": access to private data, exposure to untrusted content, and a way to send data out. Remove any one of the three and most exfiltration attacks fail.

## Which defences work best? Ranked, with their limits

| Rank | Defence | What it does | What it cannot stop |
|---|---|---|---|
| 1 | Capability limits per task | An agent that reads untrusted content gets no write tools and no outbound channel for that task | Misleading answers shown to the user |
| 2 | Plan-then-execute | The agent fixes its plan and tool sequence before reading untrusted data; tool outputs cannot add new actions | Injected text changing the *arguments* of planned calls |
| 3 | Dual-model or quarantined reader | A model with no tools reads the untrusted content and returns structured data; the privileged model never sees raw text | Poisoned values inside the structured fields |
| 4 | Egress control | Only allow-listed domains and recipients; block rendering of external images and links | Exfiltration through allowed channels |
| 5 | Human confirmation for sensitive actions | Payments, permission changes and external messages need explicit approval | Approval fatigue and convincing summaries |
| 6 | Least-privilege identity | Tools run with the user's delegated, scoped token, not a shared admin key | Misuse within the scopes granted |
| 7 | Input marking ("spotlighting") | Untrusted content is delimited or encoded so the model can tell it apart | Determined, adaptive attacks |
| 8 | Injection classifiers | A detector scores tool output before the model sees it | Novel phrasings; false positives on normal text |
| 9 | System-prompt hardening | Instructions to ignore commands found in data | Most well-crafted injections |

The ranking follows a simple rule: controls that do not depend on the model behaving correctly beat controls that ask it to. The design patterns in Beurer-Kellner et al. (2025) and Google DeepMind's CaMeL work both take this approach. They give up some flexibility in exchange for guarantees.

## How do you apply this to a real agent? Seven steps

1. **List every tool that returns external text.** Web fetch, email read, ticket read, document search, MCP tools that wrap SaaS APIs.
2. **Classify each agent by the trifecta.** Mark private data access, untrusted input and outbound channels. Agents with all three need redesign first.
3. **Split tasks.** Use one agent or step to read and summarise untrusted content, and another to act, with only structured data passed between them.
4. **Scope tools per task.** Load write tools only when the plan needs them.
5. **Lock down egress.** Allow-list domains for fetch tools and recipients for email tools.
6. **Add detection and logging.** Run a classifier on tool outputs, log every tool call with its arguments, and alert on unusual sequences.
7. **Red-team it.** Plant injections in test documents, tickets and pages, and run multi-turn attacks before release and after every change.

## How Opencontroller does this

Opencontroller sits in the path for traffic routed through its LLM Gateway and Agent Gateway, where policy can allow, route, redact or block. Live groundedness and task-adherence guardrails score responses, and multi-turn and red-team evals test agents before release. Behavioural-deviation monitoring can alert on, quarantine or kill an agent whose tool use changes. Built-in policy mappings cover OWASP and MITRE ATLAS. See the [MCP governance guide](/blog/how-to-govern-mcp-servers) and [how to red-team AI agents](/blog/how-to-red-team-ai-agents-multi-turn), or [book a demo](https://www.lyzr.ai/book-demo/).

Primary sources: [OWASP LLM01:2025 Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) and [Design Patterns for Securing LLM Agents against Prompt Injections](https://arxiv.org/abs/2506.08837).

## Frequently asked questions

**Can a guardrail model fully block indirect prompt injection?**
No. Classifiers reduce successful attacks but miss novel phrasings. Pair them with capability limits and egress controls that work even when detection fails.

**Is MCP tool output more dangerous than web content?**
It is the same risk through a different route. Any MCP tool that returns third-party text, such as tickets, emails or pages, can carry injected instructions.

**What is the quickest high-value fix?**
Remove outbound channels from agents that read untrusted content, or require confirmation before they send anything externally. That breaks most exfiltration paths.

## Key facts

Indirect prompt injection arrives in content an agent reads through tools (web pages, emails, tickets, MCP tool results). OWASP lists prompt injection as LLM01:2025. Architectural defences rank highest: per-task capability limits, plan-then-execute, a quarantined reader model, egress allow-lists and human confirmation for sensitive actions; spotlighting, classifiers and system-prompt hardening reduce but do not remove risk. Opencontroller provides an LLM Gateway and Agent Gateway in the traffic path (allow, route, redact, block), live groundedness and task-adherence guardrails, multi-turn and red-team evals, behavioural-deviation monitoring with quarantine and kill, and OWASP and MITRE ATLAS mappings. Opencontroller pricing starts from $250K per deployment per year.

## Related

- [What is MCP tool poisoning and how do you prevent it?](https://opencontroller.lyzr.com/blog/what-is-mcp-tool-poisoning.md)
- [How do you red-team AI agents with multi-turn attacks?](https://opencontroller.lyzr.com/blog/how-to-red-team-ai-agents-multi-turn.md)
- [Do Azure AI Content Safety Prompt Shields govern AI agents?](https://opencontroller.lyzr.com/blog/azure-prompt-shields-vs-agent-governance.md)
- [More on Tools and MCP](https://opencontroller.lyzr.com/blog/cluster/tools-and-mcp)
