Writing ·
How to build a prompt-injection red-team corpus for AI agents
Build a versioned corpus of executable prompt-injection cases, separate discovery from held-out release evidence, and replay protected decisions after every material agent change.
By Youssef Hemimy · agent safety · agent evaluation · AgentOps
Build a prompt-injection red-team corpus as versioned executable security cases—not a folder of clever strings. Bind each attack to its benign task, untrusted context, malicious objective, protected action, expected safe result, observed trace, and outcome. Keep attack discovery separate from held-out release evidence, then replay the suite after every material agent change.
That makes prompt-injection testing a release control. A copied payload without its task, authority boundary, and expected result is trivia. An executable case can show whether one versioned system preserved one protected decision under one recorded threat condition.
1 · Sandbox
Discover
Generate candidate attacks with synthetic identities, inert secrets, bounded tools, and no production side effects.
2 · Security review
Curate
Check authorization and provenance, normalize the case, deduplicate the mechanism, and retain scope plus failures.
3 · Versioned evidence
Replay
Run against a pinned system, inspect the protected action, and retain the trace, side effects, and final state.
Development
Find and fix failures. Never reuse this bucket as the only proof of the fix.
Held-out acceptance
Freeze before tuning. A failed protected decision blocks promotion.
Incident regressions
Preserve confirmed failures and their expected outcomes without rewriting history.
Replay the relevant slice after a model, prompt, tool, permission, retrieval, memory, policy, retry, or recovery change.
A useful corpus case is a decision record
Start with the action you are protecting. Malicious text matters only in relation to the legitimate task, the untrusted surface carrying it, and the side effect it tries to cause.
| Case field | Why it belongs in the corpus |
|---|---|
| Case ID and version | Makes failures, fixes, and replays refer to the same immutable test. |
| Benign task | Preserves what the agent was authorized to complete. |
| Untrusted context | Identifies whether the injection arrived through a page, document, message, retrieval result, or tool output. |
| Malicious objective | Names the unintended state change or disclosure being tested. |
| Protected action and authority rule | States what the agent may not do, or which approval must exist before it acts. |
| Expected safe result | Encodes execute, refuse, constrain, ask for approval, or escalate as an observable outcome. |
| System versions | Pins the model, prompt, tools, policies, and environment under test. |
| Observed trace and outcome | Separates safe-sounding prose from decisions, tool calls, side effects, and final state. |
| Attempt profile and scope | Preserves probabilistic failures and the conditions under which a strategy did or did not work. |
This schema is Bonfire operating guidance, not a standard copied from either source. NIST frames a hijacking scenario around a legitimate user task and a malicious injection task. The PIMiner preprint describes human-readable strategy files that preserve target and task scope, examples, fingerprints, and explicit failure conditions.
Separate discovery, curation, and release evidence
Discovery finds candidate attacks
Run authorized attack generation in a sandbox with synthetic identities, inert secrets, bounded tools, and no path to production side effects. Discovery may iterate, combine known strategies, and learn from failed attempts. Its output is a candidate case—not release evidence and not permission to test someone else's system.
PIMiner is relevant because it does not restart every sample from zero. In its benchmark setting, a router selects from a long-term strategy library, the attacker retains experience from earlier samples in a dataset and the current sample's history, and a digester updates strategies from successes and misses.
Curation turns discoveries into stable cases
A security reviewer should decide whether a discovery adds a distinct mechanism, risk, or coverage boundary. Normalize it into the corpus schema, remove irrelevant payload variation, retain its provenance, and record where it has and has not worked. Deduplicate by protected decision and attack mechanism, not only by string similarity.
Do not erase misses. A failed attack can show that a strategy depends on a particular tool, task shape, context slot, or target behavior. That is evidence about scope, not clutter.
A held-out suite makes the release decision
Freeze an acceptance set before tuning the candidate system. Do not let the same cases guide a defense change and then become the only proof that the change worked. NIST reports developing adaptive attacks on a subset of Workspace tasks and evaluating them on held-out tasks. The exact split is not a universal recipe; the important boundary is that discovery did not consume all acceptance evidence.
Use at least three corpus buckets:
- Development cases for finding and fixing failures.
- Held-out acceptance cases for the promotion decision.
- Incident regressions for every confirmed real or pre-production failure, preserved without quietly rewriting its expected result.
Preserve transfer evidence without claiming universal attacks
PIMiner's experiments use controlled public samples from IPIArena and AgentDojo, with separate training and test splits. The paper reports benchmark-bounded transfer of its strategy library to target models outside its training sequence, and its ablations find that the strategy library and within-dataset memory both contributed in the tested IPIArena setting.
The practical lesson is narrower than “this attack transfers.” Record the dimensions across which transfer was actually observed:
- agent and model version;
- tool and permission surface;
- benign task family and untrusted-content surface;
- malicious objective and protected action;
- action policy and confirmation boundary; and
- number of attempts and query budget.
When a strategy succeeds on another configuration, add that evidence. When it fails, preserve that too. Do not turn “worked on one benchmark target” into a claim about a private workflow, a future model, or every agent using the same framework.
Measure risk by task and repeated opportunity
An overall attack-success rate can hide the case that matters most. Record:
- Benign task completion: did the agent still complete the legitimate work?
- Malicious objective completion: did the prohibited outcome occur?
- Protected-action decision: was the request denied, constrained, approved, or escalated according to policy?
- Impact class: what would the attempted action have changed or exposed?
- Attempt profile: did the case fail once, intermittently, or whenever an attacker could retry?
NIST recommends inspecting task-specific performance in addition to aggregate results because injection tasks differ in success frequency and impact. It also recommends multiple attempts where attackers can realistically retry because model behavior can vary between runs.
Set the repeat count and release threshold from your threat model before the run. These sources provide no universal number. A read-only assistant and an agent allowed to send messages, run code, or move money should not inherit the same veto policy because a dashboard prefers one tidy average.
Promote cases with a controlled workflow
- Discover in a sandbox.
- Review authorization and provenance.
- Classify the protected action and risk.
- Normalize the finding into an executable case.
- Deduplicate by mechanism and decision boundary.
- Validate the expected outcome.
- Assign development or held-out status.
- Replay on a versioned system and retain scope, outcomes, and failures.
Require human review before a case enters the shared corpus when it contains a novel mechanism, realistic sensitive data, or a consequential action. Store attack material with access controls proportionate to its risk. Use synthetic identities and inert credentials. Verify final state instead of trusting the agent's narration.
Replay the relevant corpus slice after changes to:
- the model or model alias;
- system or developer instructions;
- tool schemas, permissions, or confirmation rules;
- retrieval, memory, or context assembly;
- content screening or policy services; or
- retries, orchestration, or recovery behavior.
Connect the corpus to enforceable controls
Use instruction-hierarchy tests to encode the expected action, refusal, or escalation. Run discovery and replay inside an isolated agent-evaluation environment. Set per-risk vetoes with AI agent release acceptance thresholds, then enforce the protected action and allowed parameters through production agent tool contracts.
What this corpus can and cannot establish
A passing corpus says that a versioned system met explicit expectations on the cases and attempts you ran. It does not prove the absence of prompt injection, cover unknown delivery surfaces, or convert a benchmark result into a production risk estimate.
The PIMiner evidence is one unreviewed preprint. Its experiments use public, sandboxed benchmarks rather than real systems, users, or private data, and the paper primarily uses Claude Code models for its red-team backbone. NIST's work is evaluation guidance, not a certification scheme.
The useful claim is deliberately smaller: this system, at this version, preserved these protected decisions under these recorded attacks. “Prompt-injection safe” is marketing fog with a clipboard.
Sources
FAQ
Is a list of known prompt injections enough?
No. Without the benign task, untrusted surface, malicious objective, protected action, expected result, and system version, a string cannot support a reliable release decision.
Should successful attacks automatically enter the release suite?
No. Review and normalize them first. A successful payload may duplicate an existing mechanism, rely on unsafe data, or lack a stable expected outcome. Keep held-out acceptance evidence separate from the cases used to tune the system.
Should failed attacks be deleted?
No. Preserve meaningful failures with their scope and configuration. They show where a strategy does not transfer and prevent a benchmark result from being generalized beyond its evidence.
How many times should each case run?
These sources provide no universal count. Choose the repeat policy before the run from impact, variance, and the attempts a realistic attacker gets, then report that attempt budget with the result.
Does a passing corpus prove the agent is secure?
No. It provides bounded evidence for the tested cases and configuration. Least privilege, deterministic action validation, approval boundaries, monitoring, and incident response still have to hold.
Building something that has to hold up?
We do this work for teams — agent reliability hardening, custom MCP servers, and full-stack AI systems built to survive production.