Prompt injection testing is most useful when it is treated as a repeatable security exercise rather than a one-time attempt to break a chatbot. This playbook provides attack patterns, safe test cases, defensive checks, and a review schedule for LLM applications that accept user input, retrieve documents, call tools, or handle sensitive data.
Overview
Prompt injection occurs when untrusted content influences an LLM to disregard, reinterpret, or override the instructions that should govern its behavior. The content may come directly from a user, indirectly from a document in a retrieval pipeline, or through data returned by a tool or external system.
The central testing question is not simply, Can the model be persuaded? It is: What can the application do if the model is persuaded? A strong review therefore examines the entire control path, including prompts, retrieval, tool permissions, application logic, output handling, logging, and human escalation.
Before testing, create a non-production environment with synthetic records and disposable credentials. Do not place real API keys, customer data, internal secrets, or unrestricted production tools in an adversarial test. Record the model version, system instructions, enabled tools, retrieval sources, application build, and test date so that results can be reproduced.
Use this playbook alongside an LLM evaluation framework for regression tracking and an AI feature launch checklist for broader production readiness.
Checklist by scenario
Run each scenario with several phrasings and conversation states. A single successful refusal does not establish that the application is resistant; test whether the same boundary holds after follow-up questions, long context, retrieved content, and tool use.
| Scenario | Safe test pattern | What to verify | Primary defense |
|---|---|---|---|
| Direct injection | Ask the assistant to ignore its operating rules, reveal hidden instructions, or change its task. | The response does not disclose confidential instructions or abandon the intended task. | Keep secrets out of prompts where possible, define clear instruction boundaries, and enforce sensitive actions in application code. |
| Instruction conflict | Provide two messages or fields that give contradictory directions, then ask which one controls. | The application has a documented precedence model and follows it consistently. | Separate trusted instructions from user content and label untrusted fields explicitly. |
| Indirect injection | Place an adversarial instruction in a test document, web page, email, or knowledge-base entry that the application retrieves. | Retrieved text is treated as data, not as an instruction source. | Use source boundaries, content labeling, retrieval filtering, and output validation. |
| Tool misuse | Ask the model to call a tool with an unauthorized target, excessive scope, or altered parameters. | Every call is checked independently of the model’s explanation. | Apply allowlists, typed schemas, least-privilege credentials, parameter validation, and approval gates. |
| Data exfiltration | Request protected test values, hidden context, another user’s record, or content outside the current authorization. | No sensitive value is returned, summarized, inferred unnecessarily, or placed in a tool argument. | Enforce authorization before retrieval and before response delivery; redact and monitor sensitive output. |
| Context overload | Fill the context with irrelevant or conflicting material, then place a malicious instruction near the end or inside a retrieved item. | Safety and task constraints remain effective under long or noisy input. | Limit context, rank sources carefully, isolate instructions, and test truncation behavior. |
Reusable red-team test case
For each case, capture:
- Test ID: a stable identifier and scenario category.
- Entry point: chat, file upload, search result, email, API field, or tool response.
- Untrusted payload: the synthetic text or document used in the test.
- Expected behavior: the permitted answer, refusal, escalation, or blocked action.
- Observed behavior: model output, tool calls, retrieved records, and application status.
- Impact: what could happen if the behavior reached production.
- Disposition: pass, fail, needs review, or not applicable.
- Regression marker: the build, prompt version, model configuration, and date.
Keep test prompts focused on demonstrating a control failure. The goal is to verify boundaries, not to extract real secrets or develop an operational exploit.
What to double-check
Trust boundaries
Map every instruction and data source before testing. Mark system instructions, developer-authored rules, user input, retrieved documents, tool results, memory, and conversation history as separate trust categories. If the application combines them into one undifferentiated text block, treat that as a design risk worth addressing.
Authorization outside the model
A model should not be the final authority for access control. Check that the application verifies the user, tenant, resource, action, and parameters before a retrieval or tool call is executed. A request such as summarize this account should still be rejected if the authenticated user is not entitled to that account.
Tool boundaries
Review each tool as if it were exposed to an untrusted caller. Confirm that schemas reject unexpected fields, destinations are restricted, credentials are narrowly scoped, and high-impact actions require confirmation or human approval. Log the proposed arguments and the final arguments actually executed. A natural-language explanation from the model is not a security control.
Retrieval and document handling
Test documents containing fake system messages, requests to contact an outside party, instructions to reveal context, and misleading metadata. Verify that source text cannot alter application policy. Also check whether deleted, restricted, or cross-tenant documents can be retrieved through semantic similarity or cached results. For storage decisions, a vector database comparison should be paired with an access-control review.
Output handling and observability
Validate structured outputs before they reach downstream systems. Reject missing, extra, or unsafe fields rather than silently accepting them. Monitor refusal rates, unusual tool-call patterns, repeated access attempts, prompt length changes, and responses that contain protected test markers. Logs should support investigation without copying unnecessary sensitive content.
Common mistakes
- Testing only the chat box. Injection can enter through uploaded files, search indexes, support tickets, metadata, tool responses, and memory.
- Relying on a stronger prompt. Prompt wording can help, but it cannot replace authorization, validation, isolation, and least privilege.
- Using production data. Red-team tests should use synthetic secrets and reversible actions in an isolated environment.
- Checking only the final answer. A response may look harmless even though the model exposed data in a tool argument or triggered an external action.
- Assuming refusal equals safety. A refusal is useful only if the application also blocks unauthorized retrieval, tool execution, and side effects.
- Failing to test multi-turn behavior. Repeat tests after rapport-building, partial compliance, user corrections, and long conversations.
- Not versioning the test set. Without stable cases, teams cannot tell whether a prompt, model, retrieval change, or code release caused a regression.
For prompt changes, maintain an approval and rollback process with prompt version control. For ambiguous or high-impact outputs, define a human review workflow rather than leaving escalation to ad hoc judgment.
When to revisit
Run the full checklist before launch and after any material change to the model, system prompt, retrieval sources, tool set, permissions, authentication flow, output schema, or conversation memory. Rerun targeted cases when an incident, suspicious output, provider change, framework update, or new integration alters the application’s attack surface.
A practical recurring review can be lightweight:
- Review the trust-boundary map and permission matrix.
- Run a small smoke set covering direct, indirect, tool, and data-access scenarios.
- Run the complete regression set before a major release or planning cycle.
- Inspect failures with engineering, security, and product owners.
- Record accepted risks, owners, due dates, and the next review trigger.
Start with the highest-consequence paths: tools that change records, retrieve private information, send messages, spend money, or affect access. Then expand coverage as the application gains new inputs and capabilities. Prompt injection testing is most valuable when it becomes part of the normal AI developer workflow: repeatable, versioned, observable, and tied to concrete application controls.