Sub topic 10
Breaking the combination of private data, untrusted input, and exfiltration
This chapter assumes you know how tool calling works and have read the earlier chapters on prompt injection, tool scoping, and enforcing authorization in code. Here you will learn a design rule that limits the damage of a successful injection. The rule is to avoid giving one agent step all three of the capabilities below.
The three capabilities
Data theft from an agent usually needs three things at once:
- Access to private data. The agent can read email, files, records, or secrets.
- Exposure to untrusted input. The agent processes text an attacker can influence, such as web pages, inbound email, tickets, or documents.
- An outbound channel. The agent can send data out, for example by sending email, making HTTP requests, or rendering a link or image that a client will fetch.
If all three are present, an attacker plants instructions in the untrusted content. The model follows them, reads private data, and sends it out. No bug in your code is needed. Every tool worked as designed.
Why prompts do not fix this
You cannot reliably tell the model to ignore injected instructions. Treat the model as something an attacker can steer. Then ask a structural question: if this step is fully hijacked, what can it reach? Removing a capability is a guarantee. A prompt warning is only a hope.
Ways to break the combination
For each agent step, list which of the three capabilities it has. Then remove at least one.
| Remove | How | Example |
|---|---|---|
| Private data | Give the step no access to sensitive sources | A web-research agent has no file or database tools |
| Untrusted input | Process only content you control or have vetted | An internal reporting agent reads only your own database |
| Outbound channel | Remove send tools, block network egress, restrict destinations | A summarizer returns text to the caller and cannot send anything |
Often the best fix is to split the work into separate steps with different permissions. One step reads untrusted content and has no private data and no outbound tools. Another step has private data but sees only structured output from the first step.
Passing data between steps safely
Splitting steps only helps if the untrusted step cannot smuggle instructions to the privileged step. Pass narrow, validated data, not free text. The quarantined step extracts fields into a fixed schema, and code checks them before the privileged step sees them.
from dataclasses import dataclass
@dataclass
class TicketSummary:
category: str
priority: int
ALLOWED_CATEGORIES = {"billing", "bug", "feature_request"}
def parse_summary(raw: dict) -> TicketSummary:
category = raw.get("category")
priority = raw.get("priority")
if category not in ALLOWED_CATEGORIES:
raise ValueError("unexpected category")
if not isinstance(priority, int) or not 1 <= priority <= 5:
raise ValueError("priority must be an integer from 1 to 5")
return TicketSummary(category, priority)A category from a closed set and an integer in a range cannot carry an instruction. Free-text fields can, so keep them out of the privileged step or label them as untrusted data and give that step no outbound tools.
Watch for hidden outbound channels
Outbound channels are not only "send email" tools. Check for:
- Markdown or HTML rendering where an image URL can carry data in its query string.
- A fetch or browse tool that accepts any URL.
- Tools that write to shared locations an attacker can read.
- Links the user may click after the agent builds them.
Restrict egress to an allowlist of hosts and strip or disable automatic rendering of model-generated URLs.
Exercise
An email assistant reads the user's inbox, drafts replies, and can send them without review. Which of the three capabilities does it have, and name two ways to break the combination?
Show answer
It has all three: private data (the inbox), untrusted input (inbound email from anyone), and an outbound channel (sending email). Two fixes: remove autonomous sending so a person reviews each draft, and split the work so the step that reads inbound email cannot send, or restrict recipients to an allowlist.
Exercise
Why is a closed set of categories a safer way to pass data from an untrusted step to a privileged step than a free-text summary?
Show answer
A value from a fixed set or numeric range cannot contain instructions, so the privileged step cannot be steered by it. Free text can carry injected instructions.