Juan Pablo García
All projects

Prompt injection lab

36 prompt injections planted in a tool-using assistant's documents, against four defenses, alone and combined. A warning cut attacks from 42% to 6%; one fake policy update beat every defense I tested.

Personal projectAuthor2026

See it work

5 steps · scroll to play
  1. 1

    One channel

    The prompt, the question and every document reach the model as one sequence, so a document can carry instructions.

  2. 2

    Indirect injection

    The attacker plants text where the assistant will read it and waits for a normal question.

  3. 3

    The lethal trifecta

    Private data, untrusted content and a way out: the assistant had all three, on purpose.

  4. 4

    Prompt-level defenses

    Undefended, 42% of attacks worked; a warning cut that to 6%, spotlighting to 3%.

  5. 5

    Design-level defenses

    An approval gate stopped every hijacking email, but leaks through the answer still went through.

One channel

The prompt, the question and every document reach the model as one sequence, so a document can carry instructions.

Indirect injection

The attacker plants text where the assistant will read it and waits for a normal question.

The lethal trifecta

Private data, untrusted content and a way out: the assistant had all three, on purpose.

Prompt-level defenses

Undefended, 42% of attacks worked; a warning cut that to 6%, spotlighting to 3%.

Design-level defenses

An approval gate stopped every hijacking email, but leaks through the answer still went through.

Problem

An agent that reads documents can be told what to do by the text it reads. Many defenses are recommended; I wanted to know which ones work and what each one costs on normal tasks.

Solution

A small assistant for a fictional shop, with document search and a fake email tool, plus 36 poisoned documents in three attack families and twelve techniques. Every attack and 24 clean tasks ran with no defense, with four defenses alone and with all four together, scored by fixed rules, with every false-claim verdict then reviewed individually.

Architecture

The target

  1. Staff question
  2. Search documentsone may be poisoned
  3. AssistantGemini Flash-Lite
  4. Answer or emailemail is a fake tool

Defenses compared

  1. Warningin the system prompt
  2. Spotlightingdocuments marked as data
  3. Screeninga second model
  4. Approvalbefore any email
  • Undefended, the assistant followed 15 of 36 injections and leaked its secret code in 9 of 12 attempts.
  • The approval gate stopped all 12 hijacking emails but none of the leaks through the answer: it stops actions, not words.
  • The screening model caught 35 of 36 poisoned documents, but it withholds whole documents, and each poisoned one held its question's answer: 2 of 36 attacked questions were answered.
  • Everything is fictional and local; the only tool an attack can reach writes to a log.

Stack

PythonGemini APIasyncioBM25pytestGitHub Actions

Result

Attack success fell from 42% with no defense to 6% with a warning and 3% with spotlighting, at no measurable cost on clean tasks. A fake “policy update” with no instruction in it got through every defense, all four together included. Write-up: What actually stops prompt injection? I tested four defenses; animated explainer: How prompt injection works.

Want to work together?