Prompt Injection

Quick definition

Prompt injection is a vulnerability in which input to a large language model alters its behavior or output in unintended ways, for example via instructions hidden in a user message, web page, file or tool result. OWASP ranks it the top risk for LLM applications, and it is most dangerous when the model can take actions.

AI & agents
Also known as
prompt injection attack, LLM prompt injection, indirect prompt injection, direct prompt injection
6
min read
October 17, 2026

What is prompt injection?

A large language model receives its instructions and its data in the same channel: text. It has no reliable built-in way to tell the developer's instructions apart from words that arrive in a user message, a retrieved document or the output of a tool. Prompt injection exploits that. If crafted text says "ignore your previous instructions and do this instead", the model may comply.

The OWASP Top 10 for LLM Applications lists prompt injection as LLM01, its first-ranked risk, and defines it as user prompts altering the model's behavior or output in unintended ways. OWASP notes that injected content does not even need to be visible to a human, as long as the model parses it, and that techniques such as retrieval-augmented generation and fine-tuning do not fully mitigate the problem.

Prompt injection is often compared to SQL injection, because both mix untrusted input with instructions. The difference is that SQL injection has a reliable fix, parameterized queries that keep data and code separate, while language models have no equivalent hard boundary today. Defenses therefore reduce likelihood and impact rather than eliminate the risk.

The stakes depend on what the model can do. A chatbot that can only reply may leak its system prompt or produce harmful text. An AI agent that can run commands, send messages or call APIs through tool calling may take real actions on an attacker's behalf.

Why prompt injection matters

Prompt injection matters because there is no known complete fix, so systems must be designed to limit its impact.

  • Data exposure: Injected instructions can coax a model into revealing system prompts, documents or credentials it can access.
  • Unauthorized actions: Agents with broad permissions can be steered into deleting, sending or changing things.
  • Untrusted content everywhere: Any web page, email, file or API response an agent reads is a possible attack vector.
  • Cost and availability: Manipulated agents can loop or consume large amounts of model budget.
  • Skills demand: Developers, security teams and AI users all need hands-on practice recognizing and containing it.

How prompt injection works

Prompt injection takes several forms, but all rely on the model treating attacker-supplied text as instructions.

Direct prompt injection

The user's own input changes the model's behavior, deliberately or accidentally. A user might instruct a support bot to disregard its rules, or phrase a request so the model reveals its configuration.

Indirect prompt injection

The model reads external content, such as a website, a document, a code comment or a tool result, that contains hidden instructions. The user may be entirely innocent; the attacker planted the text where they knew an agent would read it.

Injection through tools and MCP servers

Agents increasingly connect to external systems through APIs and MCP servers. Results returned by those tools enter the model's context and can carry injected instructions, which is why tool output should be treated as untrusted input.

Excessive agency amplifies impact

OWASP separately lists excessive agency, where a system has more functionality, permissions or autonomy than it needs. Combined with prompt injection, it turns a manipulated response into a damaging action.

Prompt injection vs jailbreaking

Jailbreaking is a form of prompt injection aimed specifically at making a model ignore its safety rules, while prompt injection is the broader class of manipulation.

  • Goal: Jailbreaks target the model's safety behavior; prompt injection can target any behavior, including data access and tool use.
  • Source: Jailbreaks usually come from the user directly; prompt injection also arrives indirectly through external content.
  • Victim: A jailbreak mainly affects the person attempting it; indirect injection can harm an innocent user whose agent read malicious content.
  • Defenses: Model-level safety training helps against jailbreaks; injection also needs architectural controls such as least privilege and isolation.

How to mitigate prompt injection

OWASP is explicit that it is unclear whether fool-proof prevention exists, so its guidance focuses on reducing impact. Its recommended strategies include:

  • Constrain model behavior: Define the model's role and limits clearly in the system prompt.
  • Validate output formats: Specify expected formats and check them with deterministic code.
  • Filter input and output: Screen for sensitive content and suspicious instructions.
  • Enforce least privilege: Give the application its own tokens and restrict the model's access to the minimum necessary.
  • Require human approval: Keep a person in the loop for high-risk actions.
  • Segregate external content: Clearly separate and label untrusted content.
  • Test adversarially: Run regular attack simulations that treat the model as an untrusted user.

Common contexts for prompt injection training

  • Secure AI development courses: Developers attack and harden a sample LLM application.
  • Security team exercises: Analysts practice detecting and investigating injected instructions in agent logs.
  • Agent evaluations: Teams test how an agent behaves when tool results contain hostile content, inside an AI agent sandbox.
  • AI user awareness: Staff learn why agents should not be pointed at untrusted content with broad permissions.

How Heropa helps

Heropa does not detect or filter prompt injection; it provides the isolated, disposable environments where teams can safely teach and test it. Each user gets a dedicated lab built from a template, so an exercise that deliberately manipulates an agent cannot reach production systems, and the environment is destroyed afterward. See sandbox environments.

With AI Lab Keys, the agent in each lab runs on its own key limited to approved models, a budget and a duration, and keys can be revoked per user or environment. That keeps the blast radius of a manipulated agent small, which is the core of OWASP's least-privilege advice.

Frequently asked questions

Can prompt injection be completely prevented?

Not with current techniques. OWASP states it is unclear whether fool-proof prevention exists. The practical approach is layered: limit what the model can access and do, require approval for risky actions, separate untrusted content, filter inputs and outputs, and test adversarially.

What is indirect prompt injection?

Indirect prompt injection happens when a model reads external content, such as a web page, email, file or tool result, that contains hidden instructions. The user did nothing wrong; the attacker planted text where an AI agent would process it.

Why are AI agents more exposed to prompt injection than chatbots?

Agents read more untrusted content and can take actions, such as running commands or calling APIs. A manipulated chatbot produces bad text, but a manipulated agent with broad permissions can delete data, send messages or spend money.

How can I safely teach prompt injection to a class?

Use isolated, disposable lab environments with test data and no production access, give each learner their own scoped and budgeted model key, and destroy environments after the session. Learners can then attack and defend a sample application without real-world consequences.

See it in action

Give every learner and buyer a real, hands-on lab

Spin up real software environments for training, demos and POCs, right in the browser.