SafePrompt · Prompt injection detection API
Get a free API key
SafePrompt
Prompt injection detection API for LLM apps and agents.
Back to blog
Ian Ho
•
6 min read

AgentDojo prompt injection: what screening every tool output did

On AgentDojo, planted attacks reached their goal 239 times in 949 agent runs with no defence. See where to check tool results, and what to do on a block.

AgentDojoAI AgentsIndirect Prompt InjectionBenchmarks

Key points

AgentDojo plants prompt injections inside the tool output a working agent reads. With SafePrompt checking every tool output, 4 of 949 planted attacks reached their goal, against 239 with no defence. The agent was GPT-4o-mini, across four suites, on 21 to 22 October 2026. Screen each tool result before it goes back to the model, and decide in your code what the agent does when a result is withheld.

Your agent reads far more text than your users type. A calendar invite, a hotel review, a bank transfer note, a message in a team channel. Any of them can carry an instruction, and the model reads that instruction as closely as it reads yours.

A filter on the chat box never sees this text. It arrives later, inside a tool result, after the user's message has already passed.

What does AgentDojo test?

AgentDojo is a public benchmark from ETH Zurich (Debenedetti et al., 2024) that puts a real agent to work. The agent gets a user task, such as paying a bill or answering a question about a channel, and the tools to do it. The benchmark plants an attacker's instruction inside data one of those tools returns. The attack succeeds when the agent carries out the attacker's task.

We ran all four of its suites: workspace, travel, banking and slack. The agent model was GPT-4o-mini and the planted attack was AgentDojo's important_instructions attack, as the benchmark README records. That came to 949 attack runs, each one recorded in the public result files.

How many planted attacks reached their goal?

With SafePrompt checking every tool output, 4 of 949 attacks reached their goal. With no defence on the same tasks, 239 did.

Agent setupAttacks that reached their goal
No defence239 of 949
SafePrompt checking every tool output4 of 949

AgentDojo, four suites, GPT-4o-mini agent, strict mode, 21 to 22 October 2026.

SafePrompt ran as AgentDojo's prompt injection detector, the hook the benchmark provides for screening tool output. Each tool result went to the production API, detector version 64fb4530, before the agent saw it. A flagged result was withheld. Outputs over 45,000 characters were checked in overlapping windows (the harness code is in the record). The run version, the mode, the suites and how an attack is counted are all set out on the benchmarks page and in the public result records.

Why check tool output and not only the user's message?

In every AgentDojo attack, the user's message is clean. The attacker never talks to your agent. They write into something your agent will read later, such as a review on a travel site or the note on an incoming payment.

A check on the user's message passes every one of these runs, because the attack is not there yet. The check has to sit where the attack arrives, which is the tool result. In this run, that is where SafePrompt sat.

What happens to the task when a tool output is withheld?

The attack stops, and so does the step that needed that output. AgentDojo counts this too, so you can see both sides on the agent security page. With no attack planted, the agent finished 64 of 97 tasks with SafePrompt checking and 68 without it. With attacks planted, it finished 131 of 949 runs with SafePrompt and 400 with no defence.

So plan the withheld case in your own code. Your agent can tell the user which source it could not use, or pass the task to a person. The sample below hands the model a short notice in place of the tool result, which lets the agent explain the gap instead of acting on it.

How do you screen tool output in your own agent?

Put one check between the tool and the model. Send the exact text the tool returned, with your API key and the end user's IP address. Withhold the result when the verdict comes back unsafe.

// Server side only. Never send the API key to a browser.
const WINDOW = 45000  // the API accepts up to 50,000 characters per check
const OVERLAP = 2000

async function checkText(text, endUserIp, timeoutMs) {
  const res = await fetch('https://api.safeprompt.dev/api/v1/validate', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.SAFEPROMPT_API_KEY,
      'X-User-IP': endUserIp,
    },
    body: JSON.stringify({ prompt: text, sensitivity: 'strict' }),
    signal: AbortSignal.timeout(timeoutMs),
  })
  if (!res.ok) throw new Error('Screening unavailable')
  const verdict = await res.json()
  if (typeof verdict.safe !== 'boolean') throw new Error('Invalid verdict')
  return verdict.safe
}

// Returns the tool output when every window passes, or null when it must be withheld.
async function screenToolOutput(text, endUserIp, timeoutMs) {
  if (!text.trim()) return text
  for (let start = 0; start < text.length; start += WINDOW - OVERLAP) {
    const safe = await checkText(text.slice(start, start + WINDOW), endUserIp, timeoutMs)
    if (!safe) return null
    if (start + WINDOW >= text.length) break
  }
  return text
}

// In your agent loop, after a tool runs and before its result goes back to the model:
const checked = await screenToolOutput(toolOutput, endUserIp, timeoutMs)
messages.push({
  role: 'tool',
  tool_call_id: call.id,
  content: checked ?? 'This tool result was withheld because it contained instructions aimed at the assistant.',
})

An HTTP error, a malformed answer or a timeout throws, so no unchecked text reaches the model. Set timeoutMs from your own agent's deadline; it applies to each window, so a very long output takes more than one. The sample sends sensitivity: 'strict', the setting the AgentDojo run used. If you prefer the SDK, npm install safeprompt gives you new SafePrompt({ apiKey }) and check(prompt, { userIP }).

The same check works on retrieved documents, web pages and messages between sub-agents. Each check judges the text you send on its own, so send each tool result as it arrives.

What SafePrompt covers

SafePrompt protects the payload. Anything coming into your AI that could compromise it, we read first and block. We do not police what your users are allowed to ask, which is why ordinary messages go straight through. These stay in your app, which keeps your agent's rules in one place:

  • Which tools the agent may call, and approval of each action it takes.
  • Review of the tool descriptions in every MCP server you install.
  • What the agent does next when a tool result is withheld.

Run it on your own agent

The harness and every per-run row are in the public repository. Point it at your own key and your own agent model, and tell us what you see.

Frequently asked questions

What is AgentDojo?

AgentDojo is a public benchmark from ETH Zurich for prompt injection against tool-using AI agents. It gives an agent a real task and a set of tools, plants an attacker instruction inside data a tool returns, and records whether the agent finished the user task and whether it carried out the attacker task.

Which text did SafePrompt check in the AgentDojo run?

Every tool output, before the agent read it. SafePrompt ran as the benchmark's prompt injection detector, the hook AgentDojo provides for screening tool results. A flagged output was withheld from the agent. Long outputs were checked in overlapping windows, so the whole output was read.

Which SafePrompt setting did the AgentDojo run use?

The run used strict mode on production detector version 64fb4530. New accounts start on balanced. To match the run, send sensitivity: strict with each request, or make strict your account default in the dashboard under Defense & Privacy.

Can I re-run the AgentDojo benchmark myself?

Yes. The harness, the detector code and every per-run row are in the public SafePrompt repository under benchmarks/external/agentdojo. The README gives the command for each suite. Run it with your own API key and an agent model of your choice.

Further reading

Protect Your AI Applications

SafePrompt checks untrusted text before your model reads it. Add the API call to your input path and use its verdict to block flagged messages, documents and tool results.

Add SafePrompt as a preferred source on Google. You tick one box on Google's own page. Google then shows you more of our posts in your own results.