Cognitive Computing Council™

What is prompt injection, and how do you prevent it?

Prompt injection tricks an AI into following an attacker’s instructions instead of yours. It’s the top security risk for AI apps, and it can’t be fully fixed. Here is how to limit it.

By Harold Bell12 min read
A document with a hidden line of text sliding into a robot’s speech bubble on a yellow circle, an attacker slipping instructions to an AI.

What is prompt injection?

Prompt injection is an attack that tricks an AI into following someone else’s instructions. The attacker writes text that the AI reads as a command. If it works, the AI ignores its rules and does what the attacker wants. That might mean leaking data, giving harmful answers or taking unwanted actions.

It’s the top security risk for AI applications. OWASP’s Top 10 for LLM applications ranks prompt injection first, as it has in every edition. OWASP is the open security community behind the widely used web application Top 10. Its ranking shapes how security teams review AI products.

The attack works because of how language models read text. They treat everything in their input as possible instructions. They can’t reliably tell your rules apart from text an attacker slipped in. That’s a design trait, not a simple bug.

No. 1 is where OWASP ranks prompt injection among risks to AI applications.

SourceOWASP Top 10 for LLM Applications

For a SaaS company, prompt injection is a question buyers now ask directly. Security reviews ask how you defend against it, especially for AI that reads customer content. A clear, layered answer helps. Claiming you’ve solved it does not.

Prompt injection is an attack where someone hides instructions in content an AI reads, so the AI follows them instead of yours. It can’t be fully prevented, so the best defense is layers that make attacks harder and limit what a successful one can do.

What is indirect prompt injection?

There are two main kinds. In direct prompt injection, the attacker types instructions straight into the AI, like asking it to ignore its rules. In indirect prompt injection, the instructions hide in content the AI reads later. The second kind is harder to spot and often more dangerous.

C3TWO KINDS OF ATTACKDIRECTATTACKERThe user typing to the AIHIDES INIn the chat or promptEXAMPLEIgnore your rulesINDIRECTATTACKERSomeone who never logs inHIDES INDocs, emails, web pagesEXAMPLEHidden text in a file

Direct attacks come from users. Someone might try to make a chatbot reveal its system prompt or break its content rules. These are often called jailbreaks. They mainly affect the person attacking, unless the AI can reach other users’ data.

Indirect attacks come from content. An attacker hides instructions in a web page, email, document or support ticket. When your AI reads it, the hidden text can take over. One overview of the UK guidance notes the attacker may never touch the AI interface at all.

Indirect attacks grow with what your AI reads. An AI that browses the web, reads email or summarizes uploaded files faces more risk. Every new content source is a new entry point. List them all when you assess the risk.

Why is prompt injection hard to stop?

Prompt injection can’t be fixed the way older attacks were. SQL injection was largely solved by keeping commands and data separate. Language models have no reliable way to do that. Instructions and data arrive in the same text.

The UK’s security agency has said so directly. In December 2025, the NCSC warned that prompt injection may never be properly mitigated in the way SQL injection was. It called language models inherently confusable. Its advice is to reduce both the chance of an attack and the damage one can do.

Common fixes only help partly. OWASP notes that neither fine-tuning nor retrieval fully stops prompt injection. Filters catch known attack patterns but miss new ones. Attackers adapt faster than filters update.

Secrets in prompts are especially exposed. Aembit’s summary of OWASP’s guidance notes teams should never treat the system prompt as a secret or a security control. Assume an attacker can read it. Keep passwords, keys and sensitive logic out of prompts entirely.

How do you prevent prompt injection?

You can’t fully prevent it, but you can make it much harder and far less harmful. The goal is defense in depth, with several layers that each catch some attacks. Focus most on limiting damage. These layers work together.

  • Limit what the AI can do, so a successful attack can’t do much
  • Mark and separate untrusted content from your instructions
  • Filter inputs and outputs for known attack patterns
  • Validate AI output before it runs as code, SQL or a command
  • Require human approval for risky actions
  • Monitor for unusual behavior and test regularly

Limiting what the AI can do matters most. If an AI can only read public help articles, an attacker can’t steal much. If it can send email and edit records, the stakes jump. Give each AI feature only the access its task needs.

Separate untrusted content clearly. Label text from documents, emails and web pages as data, not instructions. Tell the model to treat it that way. This won’t stop every attack, but it raises the bar.

Never run AI output without checks. Treat what the AI produces like any untrusted user input. Validate it before it becomes a database query, code or a system command. That blocks many of the most damaging attacks.

13% of organizations reported breaches that involved their own AI models or apps.

SourceIBM Cost of a Data Breach 2025 via VentureBeat

Keep people in charge of risky steps. Ask a person to approve actions like sending money, deleting data or emailing customers. A short confirmation step can stop an attack cold. Our guide to when a human should be in the loop covers how to design it.

Why does injection matter for AI agents?

AI agents can take actions, not just write text. They can send messages, change records, call APIs and spend money. That turns a successful prompt injection from an embarrassing answer into real harm. OWASP calls the related risk excessive agency.

C3LIMIT THE BLAST RADIUSTools the AI can useOnly what the task needsData it can reachLeast access, per userRisky actionsHuman approval firstIts outputsValidate before runningIts activityLog and monitor it

Agents often read untrusted content and act on it in the same step. An agent that reads an email and then replies is exposed to anything hidden in that email. If it also has access to other data, an attacker may be able to steal it. That chain is what makes agents risky.

Least privilege is the core defense. Give each agent only the tools and data its task needs, scoped to the current user. Avoid broad service accounts that can reach everything. Our guide to governing AI agents with customer data covers access design.

Log what agents do. Record each tool call, input and output. Unusual activity, like an agent suddenly reading many records, should raise an alert. Logs also help you investigate if an attack succeeds.

How do you test for prompt injection?

Test by attacking your own AI. Try direct attacks in the chat and indirect attacks hidden in documents, emails and pages your AI reads. Check whether the AI leaks data, breaks rules or takes unwanted actions. Record every attempt and result.

Use known attack lists and creative testers. Public collections of attack patterns cover the common cases. Skilled testers find the new ones that matter most. Our guide to AI red teaming explains how to run an exercise.

Retest after every change. A new model, prompt or tool can open new paths. Add prompt injection tests to your release checks. Our guide to testing AI before launch covers building them in.

What should SaaS do about injection?

Start with the AI features that read outside content or take actions. Those carry the most risk. Map what each one can access and do. These steps help.

  1. List every AI feature that reads untrusted content or uses tools.
  2. Cut each feature’s access down to what its task needs.
  3. Remove secrets and sensitive logic from all prompts.
  4. Add output checks and human approval for risky actions.
  5. Run a prompt injection test and fix what you find.
  6. Set up logging and alerts for unusual AI behavior.

Be honest with buyers. Say that prompt injection can’t be fully prevented, then explain your layers. Buyers trust a clear, realistic answer more than a promise of perfection. Our guide to answering the AI section of a security questionnaire shows how to frame it.

Plan for attacks that succeed. Decide how you’ll detect, contain and report a successful injection. Treat it as an AI incident with a clear owner. Our guide to building an AI incident response plan covers the steps.

Finally, keep watching the guidance. OWASP and national security agencies update their advice as attacks change. Review your defenses at least twice a year. A C³ Snapshot can identify which of your AI features are most exposed to prompt injection.

What are common prompt injection FAQs?

What is prompt injection?

An attack where someone hides instructions in content an AI reads, so the AI follows them instead of yours. It can lead to data leaks, harmful outputs or unwanted actions.

What is the difference between direct and indirect prompt injection?

Direct attacks come from a user typing instructions into the AI. Indirect attacks hide instructions in documents, emails or web pages the AI reads later.

Can prompt injection be fully prevented?

Not today. The UK’s NCSC has warned it may never be fully mitigated the way SQL injection was. Layered defenses make it harder and limit the damage.

Why is prompt injection worse for AI agents?

Agents can take actions, like sending messages or changing records. A successful attack on an agent can cause real harm, not just a bad answer.

What is the best defense against prompt injection?

Limit what the AI can access and do, keep secrets out of prompts, validate outputs, require human approval for risky actions and test regularly.

This is practical guidance, not legal advice. It’s current as of November 2026.

Related AI governance guides

A robot facing a red-flagged target with a magnifying glass on a yellow circle, testing AI by attacking it on purpose.OPERATIONALWhat is AI red teaming?A robot agent reaching toward a customer database on a yellow circle, stopped at a padlock that sits between them.OPERATIONALHow do you govern AI agents before they touch customer data?A robot with a warning triangle beside a stopwatch and a checklist on a yellow circle, a team ready to respond when AI fails.OPERATIONALHow do you build an AI incident response plan?