Concepts / Agents and Tool Use with Language Models

Agents and Tool Use with Language Models

The attack is defined by where the payload is hidden, not by a single fixed wording. Because a model can use a large number of tools, these attacks can take many shapes and forms.

  • Programming

Why a Filtered Chat Box Is Not Enough

Imagine a language model that is safe to talk to directly. Its developers have filtered what users type into the chat box, and nobody is trying to slip harmful text through that box. Yet the model can still be manipulated. The reason is that the model does not only read what the user types. Modern AI applications connect models to web search, code repositories, email, databases, and other tools. Each of those connections is a place where text enters the model's context.

Indirect prompt injection is an attack that uses those connections instead of the chat box. To understand it, it helps to follow a single instruction from where it starts to where it takes effect.

Tracing an Injected Instruction Through the System

The easiest way to understand this attack is to follow the instruction from its origin to its effect. The attacker starts somewhere outside the conversation, in a location that a tool can reach. The tool then brings that content into the model's working input. Once the model has it, the model may treat the injected text as something it should act on. Read the path as a sequence of handoffs. The user is only at the very end of the chain, not at the beginning.

Attacker-controlledlocationweb page, email,repository, or recordToolsearch, mail reader, ordatabase lookupModel's working inputretrieved text sits besidethe promptModel acts on thetextmay treat it as aninstructionUser receives theeffectthe only point where theuser appearstool reaches the locationcontent loaded into contextmodel reads everythingaction or output
Where does the malicious text enter the system, which components does it pass through, and at what point does it reach the model's context?

Notice what this path does not require. The source describes the attack as a model being able to retrieve and execute injected prompts and code. The model is doing something it was designed to do, such as searching, reading mail, or looking things up, and the injected content rides along with that normal activity. Nothing about the attack requires the user to make a mistake in the chat box.

What do you think happens?

Must the user type the malicious text for the assistant to be affected?

  • Yes, the user must paste it into the chat

  • No, it can arrive through a tool the model uses during normal work

Reveal answer
Answer:

No, it can arrive through a tool the model uses during normal work

Indirect injection places the payload in content that a tool retrieves, such as a web page or an email. The user does nothing dangerous, because the model's ordinary searching or reading brings the text in.

Direct Prompts Versus Indirect Injection

Definition

Indirect prompt injection delivers malicious instructions through tools a model is integrated with, rather than through the prompt itself.

The malicious content in an indirect attack is the same kind of text an attacker might have typed directly. What changes is the route it takes into the model. The word delivery matters here. A direct attack places the instruction in the prompt itself, where the user types it. An indirect attack places the same kind of instruction somewhere a tool will fetch it from, so it reaches the model through the tool's output.

Entry point: chatboxuser types the instructionInstruction in thepromptplaced directly in thepromptModel receives itfrom the user's own inputEntry point: toolor data sourceweb search, email,database, repositoryInstruction inretrieved contentsame kind of text,different routeModel receives itthrough the tool's outputtyped inpromptfetched by tooltool output
How does the entry point of the malicious instruction differ between a direct attack, where the user types it, and an indirect attack, where it arrives through a tool or data source?
Key point

The attack is defined by where the payload is hidden, not by a single fixed wording. Because a model can use a large number of tools, these attacks can take many shapes and forms.

Two Delivery Approaches

The source gives two example approaches to delivering indirect injections. They differ in whether the attacker waits for the model to find the payload or actively sends it to a target. Both fit the same definition, since both place instructions outside the direct prompt.

Following an Inbox Summary Attack

The source gives a daily-routine case. You ask an assistant to read and summarize your inbox. Among the messages is one from an unknown sender that contains a line written as an instruction to the assistant rather than as a note to you. The assistant reads the whole message while summarizing. Because it has no reliable way to separate that line from your genuine requests, it may follow it. The attack succeeds without you typing anything dangerous.

Worked example

Tracing the inbox attack step by step

A user asks an assistant to summarize the inbox. One unknown-sender message contains a line phrased as an instruction to the assistant. What happens, and who has to do something unsafe?

  1. 1
    Step 1: the request begins normally

    The user asks for a summary. The user types only a harmless request into the chat box.

  2. 2
    Step 2: the tool loads the content

    The assistant reads the whole message, including the line written as an instruction, because summarizing requires reading everything.

  3. 3
    Step 3: the text enters the model's input

    The injected line now sits in the model's working input alongside the user's genuine request.

  4. 4
    Step 4: the model cannot reliably separate the two

    The assistant has no reliable way to tell the injected line apart from real requests, so it may follow the line.

Result

The attack succeeds without the user typing anything dangerous. The only unsafe content came from an outside sender, and it reached the model through the normal act of reading mail.

Why Retrieval and Text-to-SQL Systems Are Exposed

The same attack applies to retrieval-augmented generation, or RAG, systems. In a RAG system, the model retrieves data from an external source and uses it when generating an answer. The source's example uses user data kept in an SQL database that the model can access. An attacker could sign up with a username such as 'Bruce Remove All Data Lee'. When the model retrieves that username and generates a query, it could interpret the name as a command to delete all data.

Attacker signs upusername holdsinstruction-like textDatabase recordusername field in user dataRetrieved textfetched during answergenerationModel generates querymay read name as a commandDatabase actioncould delete all dataTrusted promptwritten by the developerstoredretrievedmodel inputtrusted promptquery runs
In a RAG or natural-language-to-SQL pipeline, which retrieved field can carry an instruction, and how does it flow into the model's input alongside the trusted prompt?

A further point makes this harder. With language models, attackers do not need to write explicit SQL commands at all, because many LLMs can translate natural language into SQL queries. Databases usually guard against SQL injection by sanitizing inputs. The source observes that it is harder to distinguish malicious content written in natural language from legitimate content. The defense that works on rigid query syntax does not transfer cleanly to ordinary language.

Mistakes Learners Make About Injection

  • Common mistake

    Assuming only the chat box can carry a malicious instruction

    What it looks like

    A developer filters all user messages and concludes the assistant is safe.

    Why it fails

    Tools such as web search, email, and databases also place text into the model's context.

    Do this instead

    Treat every tool connection as an entry point for text.

  • Common mistake

    Thinking the user must make a mistake for the attack to work

    What it looks like

    The user only asks for an inbox summary and types nothing unsafe.

    Why it fails

    The injected content rides along with the model's normal activity of reading and searching.

    Do this instead

    Recognize that the attack can succeed during routine use.

  • Common mistake

    Believing SQL sanitizing is enough for natural-language systems

    What it looks like

    A team blocks special SQL characters but accepts free-text names into the retrieval step.

    Why it fails

    Attackers can write instructions in plain language, and that text is harder to separate from legitimate content.

    Do this instead

    Treat retrieved text as untrusted, not only rigid query syntax.

  • Common mistake

    Confusing the attack's wording with its definition, when the definition is about where the payload is hidden

Classifying a New Attack Surface

MEDIUM

A model answers questions by retrieving product reviews from a public website. An unknown reviewer has written a review containing a sentence phrased as an instruction to the model. The user only asked a normal question. Which delivery approach does this resemble, what is the entry point, and at what point does the text reach the model?

Hints
  • Ask whether the attacker had to contact the target or whether the model found the payload on its own.
  • Follow the content from the website through the retrieval tool into the model's working input.
  • The payload is classified by where it is hidden, so check which route it used.

At a glance

  • Indirect prompt injection delivers malicious instructions through tools a model is integrated with, rather than through the prompt itself.
  • The path runs from an attacker-controlled location, through a tool, into the model's working input, and the user sees the effect only at the end.
  • Passive phishing leaves payloads for the model to find, while active injection sends threats proactively to each target.
  • RAG and natural-language-to-SQL systems are exposed because ordinary-looking text can be interpreted as commands and is harder to distinguish from legitimate content.

Related concepts

More concepts starting with A