Prompt Injection Defense Guide: Checklists for RAG Apps and AI Agents
prompt securityLLM securityRAGAI agentsapplication security

Prompt Injection Defense Guide: Checklists for RAG Apps and AI Agents

TTrain My AI Editorial Team
2026-12-04
8 min read

A practical prompt injection defence checklist for RAG apps and AI agents, covering untrusted content, tools, validation, permissions, and approvals.

Prompt injection can make an otherwise well-designed AI application treat untrusted text as an instruction. This guide provides a reusable security checklist for RAG apps and AI agents, covering direct and indirect attacks, retrieval boundaries, tool permissions, output validation, data exfiltration attempts, approval gates, testing, and deployment sign-off.

Overview

Prompt injection prevention is not a matter of finding one perfect system prompt. It is an application-security process that limits what the model can trust, what it can access, and what it is allowed to do. The same principle applies whether you are building a document Q&A assistant, an internal knowledge tool, a customer-support workflow, or an AI agent that can call external tools.

A prompt injection attack occurs when content influences the model to disregard its intended task or to take an unsafe action. The content may be supplied directly by a user, hidden inside a retrieved document, returned by a web page, embedded in an email, or produced by another model. An instruction can be malicious even when it looks like ordinary business text.

Separate three concerns during design:

  • Instruction authority: which messages and data are allowed to influence behaviour?
  • Capability: which tools, records, files, and systems can the application access?
  • Action control: which outputs may be used automatically, and which require validation or human approval?

This separation is more dependable than relying on a long system prompt alone. For related guidance, see the system prompt design guide and the guide to AI agent tool calling and permission checks.

Checklist by scenario

1. Direct user prompts

Users may deliberately ask an assistant to reveal hidden instructions, bypass restrictions, or perform an action outside the intended workflow. They may also accidentally paste instructions that conflict with the application’s task.

  • Define the assistant’s task in a short, testable contract.
  • State which user requests are outside scope and how the assistant should respond.
  • Do not place secrets, credentials, private policies, or sensitive implementation details in prompts that may be exposed.
  • Treat requests to reveal system messages, hidden context, or internal tool details as untrusted requests.
  • Limit the model’s response to the minimum data needed for the user’s task.
  • Log relevant request and decision metadata without storing unnecessary personal or confidential content.

2. RAG applications and uploaded documents

In a retrieval-augmented generation workflow, documents should normally be treated as evidence, not as instructions. A retrieved page might contain text such as an instruction to ignore the user’s question, disclose another document, or call a tool. The retrieval pipeline should not grant that text authority.

  • Label retrieved passages clearly as untrusted reference material.
  • Tell the model to extract relevant facts without following instructions found inside the material.
  • Keep retrieved content separate from system and application instructions in the data structure sent to the model.
  • Apply access controls before retrieval, not only after generation, so users cannot retrieve records they are not authorised to see.
  • Filter, scan, or quarantine documents that contain suspicious instruction patterns where appropriate.
  • Return citations, document identifiers, or source boundaries so the application can inspect what influenced an answer.
  • Test poisoned documents, hidden text, misleading metadata, and instructions placed in tables, footnotes, images, or code blocks.

RAG security best practices also include controlling document ingestion. Validate file types, restrict parser behaviour, set size limits, and avoid allowing an uploaded file to decide which tools or destinations the application can use.

3. AI agents and tool calls

Agent security depends on the tools behind the model, not only on the wording of the prompt. A model that can send email, modify records, run code, access a file store, or make purchases needs explicit boundaries for every operation.

  • Give each tool the narrowest permissions needed for its task.
  • Use separate credentials and service accounts for different workflows.
  • Validate tool arguments with schemas, allowlists, type checks, and business rules.
  • Prevent the model from choosing arbitrary URLs, file paths, database queries, recipients, or shell commands.
  • Use read-only tools by default and separate read and write operations.
  • Require confirmation or human approval before irreversible, external, financial, or high-impact actions.
  • Set time, quantity, rate, and destination limits to contain repeated or unexpected calls.
  • Record the user request, selected tool, validated arguments, result, and approval decision.

4. Data exfiltration attempts

An injection may try to make the application reveal secrets, private retrieved content, system instructions, or information belonging to another user. Treat any request to copy data into an external channel as a security-sensitive action.

  • Classify data before it enters the model context.
  • Keep credentials, access tokens, and encryption keys outside prompts and model-visible text whenever possible.
  • Apply tenant and user-level access checks to every retrieval and tool operation.
  • Scan generated output for restricted fields before displaying or transmitting it.
  • Block unexpected outbound requests, attachments, or messages.
  • Use redaction and minimisation rather than assuming the model will keep sensitive data private.

The AI data privacy checklist provides a useful companion review for deciding what should be removed before information reaches an AI tool.

5. Human approval workflows

Approval should occur at the point of risk, not as a general checkbox at the end. Show the reviewer the proposed action, its inputs, its destination, and the evidence supporting it.

  • Define which actions always require approval.
  • Make approvals specific to a single action or bounded batch.
  • Prevent the model from approving its own proposed action.
  • Expire approvals when the request, destination, or parameters change.
  • Provide a safe rejection path and a way to report suspicious content.

Attack-example table

ScenarioExample influencePrimary control
Direct injectionA user asks the assistant to ignore its task and reveal hidden instructions.Instruction boundaries, refusal handling, and secret minimisation.
Indirect document injectionA retrieved document tells the model to email its contents to an external address.Treat documents as data; restrict outbound tools and require approval.
Cross-tenant exposureA query attempts to retrieve another customer’s records through a shared index.Authorise retrieval before context construction and isolate tenant data.
Unsafe tool argumentsA model-generated command contains an unrestricted path or recipient.Schema validation, allowlists, least privilege, and sandboxing.
Output-based leakageA response reproduces credentials or confidential source text.Output filtering, redaction, access checks, and limited context.

What to double-check

Instruction boundaries

Write down the authority order for your application. For example, application rules define the task; user requests define the desired outcome within that task; retrieved documents provide evidence; tool results provide data to evaluate. Do not assume the model will infer this hierarchy consistently. Represent it in the prompt, data structure, tool design, and application logic.

Keep instructions concise and distinguish them from content with explicit labels. Context-window management matters here: adding more text does not automatically make the application safer. See AI context window management for practical ways to separate instructions, examples, and documents.

Output validation

Do not treat a valid JSON response as a safe response. Validate both structure and meaning. Check enumerated values, lengths, identifiers, destinations, permissions, and relationships between fields. If the model returns a proposed database update, validate the record, fields, and user authority in application code before execution.

For high-risk workflows, use a staged design: the model proposes, deterministic code validates, and a separate approval step authorises. When feasible, test malformed output, missing fields, conflicting instructions, and plausible but unsupported claims.

Observability and incident handling

Decide what evidence you need to investigate an incident. Useful records may include a request identifier, application version, model configuration, retrieved source identifiers, tool name, validated arguments, approval status, and final outcome. Protect logs as carefully as the underlying data, and define retention that matches your privacy and security requirements.

Prepare a response for suspected injection: stop or suspend risky actions, preserve relevant evidence, revoke or rotate affected credentials, review access logs, identify impacted data, and update tests before restoring the workflow.

Deployment sign-off template

Before launch, record the following:

  • Scope: intended users, data types, tools, environments, and excluded use cases.
  • Threats tested: direct injection, indirect injection, poisoned documents, data extraction, unsafe tool arguments, and denial-of-service patterns.
  • Access controls: identity checks, tenant isolation, retrieval filtering, tool permissions, and credential boundaries.
  • Action controls: validation rules, rate limits, sandboxing, approval gates, and rollback procedures.
  • Evidence: test cases, expected outcomes, logs reviewed, and unresolved risks.
  • Owner: the person responsible for accepting risk and scheduling the next review.
  • Decision: approved, approved with conditions, or not approved.

Common mistakes

  • Relying on a system prompt as the only defence: prompts guide behaviour but do not replace access control, validation, or isolation.
  • Treating retrieved text as trusted: relevance does not establish authority. A useful document can still contain hostile instructions.
  • Giving agents broad permissions: a powerful tool increases the consequences of an unexpected model decision.
  • Checking only the final answer: unsafe tool calls or data exposure may happen before a response is shown.
  • Allowing unrestricted destinations: URLs, recipients, file paths, and queries should be constrained by application code.
  • Testing only friendly examples: include adversarial, ambiguous, malformed, and multi-step cases.
  • Ignoring non-text content: inspect metadata, images, tables, attachments, and parsed content where they can influence the workflow.
  • Failing open: if validation, retrieval authorisation, or an approval service is unavailable, pause the risky action rather than silently continuing.

Teams building AI workflows can also use the AI workflow automation approval checklist to document who can approve each step and what evidence they should review.

When to revisit

Prompt injection defence should be reviewed whenever the inputs, permissions, or execution path changes. Schedule a reassessment before a new launch, after adding a model or provider, when changing retrieval or parsing components, when introducing a new tool, and after changing data access rules. Revisit it before seasonal planning cycles if those periods bring new documents, users, destinations, or approval volumes.

Also review after a red-team exercise, an incident, a suspicious output, or a material change to the application’s system prompt. Repeat representative tests when model behaviour, framework safeguards, token handling, document parsers, or agent orchestration changes. Keep a small regression suite containing your most important attack cases, expected safe behaviour, and known limitations.

For a practical next step, copy the checklist into your project documentation and assign an owner to each item. Run one test for every external input, one permission review for every tool, and one approval review for every high-impact action. Record unresolved risks rather than hiding them, set a review date, and require sign-off again whenever the workflow changes. That routine turns prompt injection prevention from a one-time prompt exercise into an ongoing part of building secure AI applications.

Related Topics

#prompt security#LLM security#RAG#AI agents#application security
T

Train My AI Editorial Team

AI Development Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.