It is an input reality.

If your AI product reads user text, retrieved text, or tool outputs, it will eventually see adversarial input that tries to override instructions, extract secrets, or manipulate tool behavior.

This guide shows how to test prompt injection in a way that is:

TL;DR
  • Test injection at the boundaries: user messages, retrieved text, tool outputs, and system-context assembly.
  • Define pass rules in one sentence per test (“must refuse,” “must not reveal,” “must ask for confirmation,” etc.).
  • Ensure injection tests cover tool safety and permission gates, not only text refusal.
  • Include RAG-related injection cases (retrieved instructions) if you use retrieval.
  • Always test fallback UX (what the user sees when protection triggers).

Where prompt injection shows up in real products

Injection usually comes from one of these places:

You are not testing whether the model is “good.” You are testing whether your product assembly and policies keep the model on the safe path.

The injection testing sequence

1) Map your injection boundaries

Write down where your system can accept instructions:

Then pick the highest-risk junctions:

2) Define pass rules before you run prompts

For each test, define what “pass” means as one sentence:

Write these pass rules down. If you skip this step, you will argue about the output instead of measuring it.

3) Run a small, layered injection set

You do not need hundreds of prompts. You need coverage of the predictable patterns.

Layer your set like this:

If you have limited time, pick 2–3 prompts per layer for a first pass and then expand based on what you learned.

What to measure (beyond “did it refuse?”)

Refusal is good. It is not the whole story.

Measure:

  1. Whether the assistant reveals hidden context (system prompts, internal instructions, secrets).
  2. Whether unauthorized tool actions are attempted, and what the product does if the model tries.
  3. Whether the user gets a safe fallback UX (clear refusal, guidance, and safe next steps).
  4. Whether the product logs safely (injection strings and “secrets” should not land in places you would not store normally).
  5. Whether the assistant cites or follows retrieved malicious instructions when you have RAG.

Prompt injection tests should result in product decisions, not only model opinions.

Worked example: injection against tool safety

Imagine your assistant can send an email (write action) after the user approves.

Injection probe idea:

Pass rule:

If you only test the assistant text and not the tool execution path, you will miss the real vulnerability.

Worked example: injection inside retrieved text

If you use RAG, test with retrieved chunks that contain instruction-like text.

Injection probe idea:

Pass rule:

How GenCodeQA approaches it

We test prompt injection as a product failure mode:

Findings are severity-ranked with fix guidance and retest support.

Method overview: AI evaluation framework.

Free tool: start with an adversarial pack

Adversarial Prompt Pack (free, no signup)

Start there, then write pass rules based on how your product is supposed to behave.

When to get a second pair of eyes

If you are close to launch and you can’t honestly answer:

Consider an independent pass. Book a free testing triage.

FAQ

Do we need to “red team” like a security firm?

Not always. You need a repeatable product probe set with pass rules. Red teaming is optional; coverage and correctness are not.

Is prompt injection only about system prompts?

No. It is also about tool calls, tool outputs, and context assembly. Text leakage is one symptom; unsafe action is another.

Will this work if we swap the model?

Swap the model, re-run the tests. Injection behavior can change, even when your policies remain the same.