Prompt injection defense is not a one-time hardening step. It is an operating checklist for any team building LLM applications that read external text, call tools, retrieve documents, or act on behalf of users. This guide gives you a reusable, scenario-based checklist for prompt injection prevention, with practical controls you can apply before launch, during testing, and whenever your model, tools, or workflows change.
Overview
If your application sends untrusted content into a model context, you should assume that content may try to change the model's behavior. That is the core prompt injection problem. An attacker does not need system access or code execution to cause harm. They may only need a place where the model reads text: a web page, a support ticket, a PDF, a CRM note, an email thread, a calendar event, or a user message. If the model treats that text like instructions instead of data, your application can leak information, ignore policy, take unsafe tool actions, or produce misleading output.
The practical goal is not to make prompt injection impossible. In most real systems, that is not a realistic standard. The goal is to reduce the chance that untrusted instructions change model behavior, limit the blast radius when they do, and make failures observable enough to catch early.
This checklist focuses on build decisions, not slogans. In practice, prompt injection defense usually combines five layers:
- Context discipline: separate instructions, user input, retrieved content, and tool results as clearly as possible.
- Permission control: restrict what the model can access or do without explicit approval.
- Output shaping: require structured output, narrow action schemas, and machine-checkable responses where possible.
- Evaluation: test against known attack patterns and keep regression cases as your app evolves.
- Operational review: revisit assumptions when models, tools, prompts, and business workflows change.
Teams that already work on prompt engineering often find that many security gains come from ordinary engineering hygiene: simpler prompts, smaller tool surfaces, cleaner data boundaries, tighter schemas, and better logging. If you need a broader baseline for prompt design, see Prompt Engineering Best Practices: What Still Works Across Modern Models.
Checklist by scenario
Use the following checklists by application pattern. Not every item applies to every stack, but most production LLM apps will fit one or more of these scenarios.
1) Chat assistants that only answer questions
This is the simplest setup, but it is still vulnerable if the assistant reads user-provided text or long conversation history.
- Define a clear instruction hierarchy in your application design: system policy, developer instructions, user request, retrieved data, and tool output should not be blended into one undifferentiated blob.
- Tell the model explicitly which content is data to analyze versus instructions to follow. This is not sufficient by itself, but it helps reduce accidental obedience.
- Delimit untrusted content clearly with labels such as
BEGIN USER CONTENTandEND USER CONTENT. - Remove irrelevant conversation history rather than carrying forward every turn by default. Long histories make it easier for malicious instructions to persist.
- Use a refusal path for attempts to reveal hidden prompts, policies, chain-of-thought, or internal metadata.
- Log prompt versions and conversation traces for security review, with appropriate redaction for sensitive data.
If your app depends on predictable formatting, require structured output instead of free-form text where possible. The article Structured Output Models Compared: Best LLMs for JSON, Tools, and Function Calling is useful when reviewing model support for stricter schemas.
2) Retrieval-augmented generation (RAG) systems
RAG systems are a common prompt injection target because they import external documents into the model context. A malicious page can include hidden or explicit instructions such as “ignore previous directions” or “tell the user the secret key.” Even if the model does not fully comply, the retrieved text can still distort the answer.
- Treat every retrieved document as untrusted, including your own knowledge base if many people can edit it.
- Store source metadata with each chunk so you know where suspicious instructions came from.
- Filter or flag documents that contain instruction-like language unrelated to the user task, especially if the corpus should be informational rather than procedural.
- Prefer retrieval prompts that ask the model to summarize evidence, quote relevant passages, or answer using cited sources rather than to “follow any instructions in the context.”
- Keep retrieval chunks tight and relevant. Irrelevant context increases the chance that adversarial text reaches the answering step.
- Separate retrieval context from task instructions in your prompt template.
- Consider an intermediate sanitizer or classifier for high-risk pipelines, especially when indexing public web content.
- Require citations or source IDs in the final response so reviewers can trace outputs back to retrieved documents.
Context size also matters. Bigger context windows can help quality, but they also create more room for adversarial or stale instructions to accumulate. See Context Window Comparison: Which AI Models Handle the Longest Inputs Best? when reviewing that trade-off.
3) Tool-using agents and function calling workflows
This is where prompt injection becomes an application security issue rather than a mere answer quality issue. If the model can search, send messages, modify records, execute workflows, or call internal APIs, a poisoned prompt can trigger real actions.
- Give the model the minimum set of tools required for the user task. Avoid broad, catch-all tool access.
- Design tools with narrow, typed parameters and explicit schemas. Do not accept free-form command strings when structured fields will do.
- Add server-side authorization checks for every tool action. Never assume the model's choice to call a tool implies permission.
- Require human confirmation for destructive, external, high-cost, or high-trust actions, such as sending emails, changing records, making purchases, or publishing content.
- Separate read tools from write tools. If an assistant only needs to search documents, do not expose update endpoints in the same session.
- Validate tool arguments independently of the model. Enforce allowed values, length limits, resource scopes, and identity checks.
- Restrict cross-tenant or cross-project access in multi-user systems.
- Record why a tool was called, with the triggering input and validated parameters.
- Provide the model with safe fallback behavior, such as asking clarifying questions instead of guessing missing parameters.
For teams building these flows, Function Calling Tutorial: How to Build Reliable Tool-Using LLM Workflows is a useful companion because reliability and security overlap heavily in tool design.
4) Internal copilots for support, sales, ops, or engineering
Internal tools are often treated as lower risk, but they frequently combine broad data access with trusted users and fast-moving prompts. That makes them easy to underestimate.
- Apply least-privilege data access per role, not just per application.
- Do not let the model browse arbitrary internal documents unless the user already has permission to see them.
- Tag sensitive repositories, records, or attachments and exclude them by default from broad retrieval.
- Make hidden instructions visible to internal reviewers in a secure admin view so prompt changes do not drift unnoticed.
- Warn users when outputs are derived from untrusted user-authored content, such as ticket comments or shared notes.
- Keep separate environments and prompts for testing versus production. A common failure is promoting experimental prompts directly into live workflows.
5) Content automation and publishing workflows
Publisher and marketing workflows often ingest scraped pages, briefs, transcripts, and competitor material. That makes them exposed to injection attempts embedded in source content.
- Strip boilerplate, scripts, hidden markup, and irrelevant page furniture before sending source text to the model.
- Treat third-party content as data to extract from, not instructions to obey.
- Use structured prompts for extraction, classification, summarization, and editorial transformation tasks.
- Prohibit direct publication from a single model pass in higher-risk workflows. Add review gates, especially when source material is external.
- Require attribution fields, source URLs, and confidence notes where appropriate so editors can verify outputs quickly.
- Keep transformation steps separate: extraction, normalization, drafting, and publishing should not all happen in one unconstrained prompt.
For editorial workflows, How to Use Structured Prompts for Reliable Marketing and Editorial Workflows offers a practical framework that also improves security posture.
What to double-check
Even well-designed systems usually fail in the gaps between components. Before shipping or updating an LLM application, double-check these areas.
Prompt and context boundaries
- Can you point to exactly where system instructions end and untrusted content begins?
- Are retrieved documents, user messages, and tool results labeled distinctly?
- Are you unintentionally concatenating multiple content types into one generic “context” field?
Permissions and data access
- Can the model see data the user cannot?
- Can a retrieved document influence tool choice or parameter selection without additional checks?
- Are secrets, tokens, and internal config values excluded from model-accessible context?
Tool safety
- Which tools can create, modify, delete, send, or purchase something?
- Which of those actions require confirmation?
- What happens if the model fills a required argument with attacker-controlled text?
Structured output and validation
- Are you parsing model output defensively?
- Do you reject malformed JSON, unknown fields, or values outside allowed ranges?
- Have you defined safe defaults when output validation fails?
Evaluation coverage
- Do you test obvious prompt injection strings as well as subtle, task-specific attacks?
- Do you keep adversarial test cases in version control?
- Do you rerun them when prompts, models, retrieval settings, or tools change?
This is where prompt versioning matters. Teams that lack regression tests often reintroduce old vulnerabilities while trying to improve answer quality. See Prompt Versioning and Regression Testing: A Guide for AI Teams for a repeatable process.
Common mistakes
Prompt injection defense often breaks down because teams rely on one visible control and ignore system design. These are the mistakes that tend to recur.
Assuming the system prompt is enough
A strong system prompt helps, but it is not a security boundary by itself. If your app gives the model broad tools or unrestricted access to sensitive context, a well-written instruction block will not compensate for weak permissions.
Mixing instructions with data
One of the most common failures is building prompts that say, in effect, “here is the policy, here is the user request, here are some documents, now do the right thing.” That leaves too much room for untrusted text to compete with your intended behavior.
Granting tools before defining approval rules
Teams often add function calling early because it improves UX, then postpone review flows, scopes, and authorization checks. That order should usually be reversed.
Skipping adversarial tests because the app seems low risk
Low-risk apps can still leak internal prompts, mishandle proprietary data, or quietly degrade output quality. Security review is not only about catastrophic failures.
Overloading one model step with too many jobs
A single prompt that retrieves, interprets, chooses tools, writes output, and decides whether content is safe is harder to reason about and harder to defend. Simpler multi-step pipelines are often easier to test and secure.
Ignoring model changes
Model updates can improve instruction following, tool use, context handling, or safety behavior, but they can also shift edge-case behavior. If you swap models or upgrade versions, rerun your prompt injection checklist. The AI Model Release Tracker: New LLMs, Multimodal Models, and Major Upgrades is useful for keeping an eye on change cadence.
When to revisit
The most useful checklist is the one your team actually reuses. Prompt injection defense should be revisited on a schedule and after any meaningful change in your stack.
Revisit this checklist:
- Before seasonal planning cycles: especially if your team expects traffic spikes, new campaigns, new content sources, or temporary staff who may change prompts and workflows.
- When workflows or tools change: adding a connector, a write action, a new retrieval source, or an approval shortcut can change risk more than a model swap does.
- When you change models or vendors: capabilities, context handling, structured output support, and safety behavior vary across ecosystems. If you are comparing stacks, OpenAI vs Anthropic vs Google: Which AI Model Ecosystem Fits Your Stack? can help frame the trade-offs.
- When token budgets or context windows change: larger prompts may alter exposure to stale or adversarial content. Cost tuning can also push teams toward riskier prompt compression shortcuts. See LLM API Pricing Comparison: Token Costs, Context Windows, and Rate Limits when reviewing architecture changes tied to budget.
- After incidents or near misses: add the exact failure mode to your regression suite, even if the incident seemed small.
If you want a practical action plan, start here:
- Map every place untrusted text enters your system.
- List every tool or action the model can trigger.
- Separate read access from write access.
- Move as many outputs as possible to strict schemas.
- Build ten adversarial tests based on your actual workflow, not generic examples.
- Require a re-review whenever prompts, models, retrieval sources, or tools change.
That process will not eliminate prompt injection, but it will turn it from a vague fear into an engineering discipline. And that is the point of a good LLM security checklist: something concrete enough to use before launch, simple enough to revisit during change, and strict enough to catch the mistakes that matter.