Test prompt injection across a multi-step AI workflow
A prompt-injection test is successful only when it checks what happens across the full workflow, not merely whether one model response refuses an attack. Trace untrusted content from its real input channel through later stages and observe whether it causes unauthorized disclosure or tool effects. Use dummy data and isolated tool substitutes.
A prompt-injection test is successful only when it checks what happens across the full workflow, not merely whether one model response refuses an attack. Trace untrusted content from its real input channel through later stages and observe whether it causes unauthorized disclosure or tool effects. Use dummy data and isolated tool substitutes.
This guide is for LLM applications that connect retrieval, summarization, planning, and tool execution. It presents a repeatable test design, not a product-specific penetration-test procedure or proof of complete security.
Define the security goal and data path
“Block injection” is not a measurable pass condition. State what must be protected and what unauthorized outcome to prevent: for example, reading another customer’s records, issuing a refund the user did not request, or sending email because an external document said to. Map each node in the actual workflow—such as a classifier, retriever, document parser, summarizer, planner, approval check, and execution tool—and record what enters and leaves it. Mark where trusted instructions, retrieved documents, tool results, and model-generated summaries meet or move to another stage. Those boundaries are test points.
Build a safe, reproducible harness
Use test accounts, dummy customers and documents, isolated storage, and tool substitutes. A substitute should record arguments and intended state changes instead of sending mail, charging money, or modifying production data. Use synthetic marker values in tests; never put real credentials or personal data in a prompt.
For each case, specify the entry channel, legitimate task, prohibited outcome, and observable evidence. To test indirect injection in a retrieved document or tool result, put it in that actual channel; placing it in the user message exercises a different boundary. Attach fixed fixtures and expected outcomes so the case can be repeated.
Test propagation between stages
Combine where an attack enters, which boundary it crosses, and what it tries to cause. In a hypothetical support workflow—classify request → retrieve order → summarize record → propose refund → call refund tool—put an instruction in a dummy retrieved note to refund another order. Check whether the summarizer treats it as data, the planner turns it into a new goal, and the final tool boundary rechecks the original request and customer authority.
Vary the entry point (user text, retrieved page, email, tool result), the stage (extraction, summary, memory, handoff), and the objective (unauthorized access, tool call, or disclosure). Include hidden text, other languages, and multi-turn variants when they match supported inputs. Add benign controls that contain similar words but request legitimate work. A malicious sentence appearing in a result is not by itself a failure; the question is whether a later step follows it or turns it into an unauthorized action.
Grade observable outcomes, not refusal wording
A final “I can’t do that” may hide a tool that already ran. For each objective, inspect whether a synthetic secret appeared in the response or test destination, whether an unauthorized tool call was proposed, approved, or executed, and whether dummy state changed. If an external effect occurred, a safe-looking final answer is not a pass.
Record outcomes separately as violation observed, no violation observed, inconclusive, or not applicable. Missing traces and test-tool errors are inconclusive, not successful blocks. Test benign requests separately and report task completion and false-positive blocking. Do not combine detection, unauthorized actions, disclosure, and benign blocking into one score.
Inspect traces and repeat
Connect each stage’s input source and output with tool name, arguments, result, authorization decision, and state change. This can show, for example, that retrieval returned an injected note, a summary repeated it, and a planner converted it into a tool argument. OpenAI’s tracing documentation describes inspecting recorded model responses, tool calls, delegated steps, and their recorded inputs, outputs, and status in an agent run.
Record case ID, entry channel, model and prompt versions, defense settings, repetitions, and observations. Keep logs to the minimum needed for debugging; do not copy secrets or unnecessary personal information. Repeat cases because model outputs can vary, and expand the corpus to the channels and languages the application supports.
Use failures to guide release decisions
When a case fails, locate the boundary where data became an instruction or where an authorization check was missing. Fix that control, then rerun the same attack and benign controls as regression cases. Enforce tool permissions and argument validation in execution code, outside the model. Test results are evidence about the cases and paths exercised; they do not prove that every attack variant is absent.
In short, define protected outcomes, test through the real channels and all later stages with dummy data, and grade security effects and legitimate task completion separately. This makes failures actionable without overstating what a test can prove.
References
[Anthropic: Mitigate jailbreaks and prompt injections](https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/mitigate-jailbreaks) — Red-team workflows before deployment with injected documents, emails, and tool outputs; check screening and confirmation steps.
[OWASP Cheat Sheet Series: LLM Prompt Injection Prevention](https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html) — Safe fixtures, actual indirect-input channels, benign controls, outcome grading, and limits of repeated tests.
[OpenAI API: Tracing](https://developers.openai.com/api/docs/guides/agents-api/tracing) — Recorded inputs, outputs, status, model responses, tool calls, and delegated steps in agent traces.