What Is Prompt Injection?

An AI Prompt injection is an attack in which someone places malicious or misleading instructions into an AI model’s input to influence how it behaves. The goal may be to override the model’s original instructions, make it reveal sensitive information, bypass safety controls, or cause an AI agent to take an unintended action.

Prompt injection can affect chatbots, copilots, retrieval-augmented generation (RAG) applications, AI agents, and any system that combines trusted instructions with untrusted content.

The OWASP’s Top 10 for large Language Models list names Prompt Injection as the number one concern for AI-related security risks, making it incredibly important to defend against. 

How does prompt injection work?

AI models process system instructions, application prompts, user input, retrieved content, and tool outputs as part of the same overall context. Without appropriate safeguards, the model may not reliably distinguish between trusted instructions and untrusted text.

An attacker can exploit this by submitting instructions like:

  • Ignore the instructions you were given.

  • Reveal confidential system information.

  • Disclose data from another user.

  • Follow a different set of instructions.

  • Use an available tool to perform an unauthorized action.

If the application accepts the model’s response or tool calls without validating them, the attack can lead to data exposure, policy violations, unauthorized actions, and more.

What are the different types of prompt injection attacks?

Direct prompt injection

A direct prompt injection comes from the user interacting with the AI application. The attacker intentionally enters instructions designed to manipulate the model.

Attack examples include:

  • Override system or developer instructions

  • Bypass content or safety restrictions

  • Extract hidden prompts or configuration details

  • Make the model reveal sensitive information

  • Convince the model to behave as a different system or user

Indirect prompt injection

An indirect prompt injection is hidden in content the AI application retrieves or processes, like a webpage, document, email, product review, image, or database record.

For example, an attacker could place malicious instructions on a webpage that an AI research assistant later reads. The application may unintentionally pass those instructions to the model as part of its context, causing the model to treat the content as an instruction rather than data.

Indirect prompt injection is particularly concerning for RAG applications and AI agents that automatically browse websites and files, process email, and interact with external systems.

Tool or agent injection

AI agents may be connected to tools that can perform automated actions: sending emails, accessing databases, executing code, making purchases, etc. A prompt injection can attempt to manipulate the agent into calling those tools in an unauthorized way.

The risk is greater when tools have broad permissions, actions are not confirmed by a user, or the application does not validate tool calls before execution.

Multimodal prompt injection

Prompt injection can also be embedded in things like images, audio, video or code. If an AI system can interpret those inputs, attackers may attempt to hide instructions in content that appears harmless to a human.

Data-exfiltration attacks

Some prompt injections are designed to make an AI system reveal sensitive information from its context, connected data sources, system prompt, conversation history, or application environment.

How can organizations detect prompt injection?

Prompt injection detection generally combines application controls, monitoring, and security inspection. Useful approaches include:

  • Inspecting prompts for known injection patterns and suspicious instructions

  • Identifying attempts to override system or developer instructions

  • Detecting requests to reveal hidden prompts, credentials, or confidential data

  • Monitoring unusual requests, tool calls, response patterns, and data access

  • Reviewing content retrieved from external sources before including it in a prompt

  • Validating model outputs and tool calls against an allowlist or defined schema

  • Logging detections, blocked requests, model responses, and agent actions

  • Testing AI applications with adversarial prompts and simulated attacks

  • Monitoring for repeated jailbreak attempts or unusual activity from the same user or source

Detection is not perfect. Prompt injection can be semantic, context-dependent, and intentionally designed to look like normal language. For that reason, detection should be combined with access controls, least-privilege permissions, output validation, and human review for high-impact actions.

Jailbreaking vs. prompt injection - what’s the difference? 

Jailbreaking and prompt injection both attempt to manipulate an AI system, but they target different weaknesses. 

Jailbreaking typically tries to bypass a model’s built-in safety rules by crafting prompts that persuade it to produce restricted content. 

Prompt injection embeds malicious instructions in user input, documents, websites, or other data to manipulate an AI application into ignoring its intended task or taking unauthorized actions. 

In short, jailbreaking targets the model’s safeguards, while prompt injection targets the application’s instructions, data, or connected tools.

How can organizations prevent prompt injection?

No single control eliminates prompt injection risk, but organizations can reduce exposure through a defense-in-depth approach.

Separate instructions from untrusted content

Clearly distinguish system instructions, developer instructions, user input, and retrieved content. Treat external content as data rather than as an instruction source.

Limit model and agent permissions

Give AI applications and agents only the access they need. Use least-privilege permissions for databases, APIs, files, tools, and internal systems.

Require confirmation for sensitive actions

Require explicit user approval before an AI system sends communications, changes records, makes purchases, executes code, or performs other high-impact actions.

Validate tool calls

Check every tool call against the user’s permissions, the application’s policy, and the expected request structure. Do not allow a model to determine its own authorization.

Validate model outputs

Use structured outputs, schemas, and allowlists where possible. Do not automatically trust a model response simply because it is syntactically valid or appears confident.

Minimize sensitive information in prompts

Only provide the model with the information needed to complete the task. Redact credentials, personal information, financial data, and other sensitive content wherever possible.

Filter retrieved content

Scan and classify documents, webpages, emails, and other external data before including them in a model context. Maintain provenance so applications know where content came from.

Apply rate limits and usage controls

Limit requests, tokens, tool calls, and agent actions. This can reduce abuse and help contain the impact of automated injection attempts.

Log and review AI activity

Maintain appropriate records of prompts, completions, tool calls, policy decisions, and security detections. Use those records to investigate incidents and improve controls.

Keep traditional application security in place

AI applications still rely on websites, APIs, identity systems, and infrastructure. WAF, API security, bot management, DDoS protection, authentication, and secure software development practices remain important parts of the overall defense.

What does Fastly offer to help protect against prompt injection?

Fastly AI Firewall is designed to protect AI-enabled applications from LLM-specific attacks, including prompt injection and jailbreak attempts. It operates in the request path and evaluates prompts before they reach the targeted model.

When used with Fastly AI Runtime Control, AI Firewall can:

  • Inspect requests for prompt injection and jailbreak attempts

  • Apply detection before requests are forwarded to an AI provider

  • Wrap untrusted user input with boundary markers to help distinguish data from instructions

  • Inspect responses for evidence that an injection attempt reached the model

  • Log detections or block malicious requests, depending on the configured policy

  • Provide detection tags and threat classifications alongside request details

Fastly AI Runtime Control provides the control layer around model traffic, including centralized routing, virtual keys, rate limits, token limits, usage visibility, logging, and provider failover. AI Firewall is an optional security add-on within that workflow.

Fastly’s broader security platform can also help protect the surrounding AI application and infrastructure. Next-Gen WAF, API Security, Bot Management, DDoS Protection, ContentGuard, and API Discovery can help secure the web applications, APIs, agents, and external AI traffic connected to AI systems.

¿Estás listo para empezar?

Ponte en contacto con nosotros hoy