What Is a Prompt Injection Attack? Prompt Injection in AI Explained

A prompt injection attack happens when text given to a large language model changes its behaviour in ways the developer did not intend. In direct injection, a user types instructions that override the system's rules. In indirect injection, the instructions are hidden in content the model reads, such as a web page, email, document or code comment.

May 19, 2025 - 12:51
Updated: 
102.3k

AI Security & Governance in AI & Data · Explainer

What Is a Prompt Injection Attack? Prompt Injection in AI Explained

Quick answer: A prompt injection attack happens when text given to a large language model changes its behaviour in ways the developer did not intend. In direct injection, a user types instructions that override the system's rules. In indirect injection, the instructions are hidden in content the model reads, such as a web page, email, document or code comment. OWASP ranks prompt injection as LLM01, the top risk in its 2025 list for LLM applications. It can cause data leaks, harmful output or unwanted actions by AI agents. No single fix stops it, so defenders limit what the model can access and do, and keep humans in the loop.

Key takeaways

  • Prompt injection exploits the fact that LLMs mix instructions and data in one text stream.
  • Indirect injection is the bigger risk for agents that browse, read email or use tools.
  • Jailbreaking is a form of prompt injection aimed at bypassing safety rules.
  • OWASP says it is unclear whether fool-proof prevention exists.
  • Least privilege, output checks and human approval reduce the impact.

Table of Contents

What Is Prompt Injection in Simple Terms?

An LLM application usually combines a developer's system prompt, the user's message and extra content such as search results. The model sees all of it as text. If some of that text contains instructions, the model may follow them. The OWASP LLM01:2025 entry defines a prompt injection vulnerability as user prompts altering the model's behaviour or output in unintended ways. MITRE catalogues it as ATLAS AML.T0051.

What Is the Difference Between Direct and Indirect Prompt Injection?

TypeWhere the instruction comes fromExample scenario
DirectThe user's own inputA user tries to make a support bot ignore its rules
IndirectExternal content the model processesA web page with hidden text tells a browsing assistant to leak chat history
MultimodalInstructions inside images or filesText embedded in an image read by a vision model

NIST AI 100-2 E2025 describes both direct and indirect prompt injection in its taxonomy of attacks on generative AI.

Why Is Prompt Injection So Hard to Fix?

Traditional injection flaws such as SQL injection are fixed by separating code from data. LLMs have no reliable boundary between instructions and data, and their output is probabilistic. Filters catch known patterns, but attackers can rephrase. That is why OWASP treats prompt injection as a risk to manage, not a bug to patch once.

What Damage Can Prompt Injection Cause?

ImpactRelated OWASP 2025 risk
Leaking system prompts or private dataLLM02 Sensitive Information Disclosure, LLM07 System Prompt Leakage
Agents sending email or changing recordsLLM06 Excessive Agency
Malicious output passed to other systemsLLM05 Improper Output Handling
Misleading answers to usersLLM09 Misinformation

The full list is in the OWASP Top 10 for LLM Applications 2025. For a real-world agent case, read how prompt injection exposed gaps in an AI coding agent.

How Do You Defend an LLM Application Against Prompt Injection?

  1. Least privilege: give the model only the tools and data it needs.
  2. Human approval: require confirmation for sending, paying, deleting or sharing.
  3. Separate untrusted content: label external content clearly and never let it change permissions.
  4. Input and output filtering: services such as Microsoft Prompt Shields detect many attack attempts.
  5. Validate output: treat model output as untrusted before it reaches code, databases or browsers.
  6. Monitor and log: record prompts, tool calls and blocks for investigation.

The joint Deploying AI Systems Securely guidance and the NIST AI RMF support these controls at the organisational level. Our sibling guide on preventing prompt injection in LLMs like ChatGPT goes deeper into chatbot mitigations.

How Should Teams Test for Prompt Injection?

Test only systems you own or have written permission to assess. In India, unauthorised testing can breach Sections 43 and 66 of the IT Act 2000. Build a test plan covering direct and indirect inputs, tool misuse and data exposure, and repeat it after every model or prompt change. Report incidents involving data exposure to CERT-In within 6 hours.

How Can You Learn AI Security?

Start with web application security, then study the OWASP LLM Top 10 and NIST guidance. WebAsha Technologies offers AI security and ethical hacking training focused on defence.

References

Frequently Asked Questions

An attack where text given to a large language model changes its behaviour in unintended ways, such as ignoring rules or leaking data.

Instructions hidden in content the model reads, such as web pages, emails or documents, rather than typed directly by the user.

OWASP treats jailbreaking as a form of prompt injection that specifically aims to make the model ignore its safety rules.

It is LLM01, the first entry in the OWASP Top 10 for LLM Applications 2025.

OWASP says it is unclear whether fool-proof prevention exists, so teams combine least privilege, filtering, output validation and human approval.

Agents read external content and can take actions, so hidden instructions can trigger real effects such as sending data or changing records.

Only on systems you own or have written permission to test. Unauthorised testing can breach Sections 43 and 66 of India’s IT Act 2000.

OWASP LLM01:2025, NIST AI 100-2 E2025, MITRE ATLAS AML.T0051 and the NIST AI Risk Management Framework all address it.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.