Prompt Injection
Prompt injection is an attack on applications built on large language models (LLMs) in which untrusted input, combined with a prompt written by a higher-trust party such as the application designer, alters the model's behavior or output in unintended ways.
Updated
Overview
NIST describes prompt injection as an attack that exploits the concatenation of untrusted input with a prompt constructed by a higher-trust party. In a direct prompt injection, the main user of the system provides instructions that are appended to higher-trust instructions such as the model's system prompt. An indirect prompt injection depends on the attacker's ability to modify external sources of information, such as websites or files, that the application feeds into the model's context. A third party mounts it, and the primary user of the model is often the one harmed.
Injected content does not need to be visible or readable to a human, as long as the model parses it. The impact depends on the business context and on how much agency the model has. It can include disclosure of sensitive information, revealing system prompts or details of the AI system's infrastructure, incorrect or biased output, unauthorized access to functions available to the model, and arbitrary commands in connected systems.
OWASP states that, given the stochastic way models work, it is unclear whether fool-proof prevention exists. Its mitigations limit the impact instead. They include constraining model behavior in the system prompt, validating output formats with deterministic code, filtering input and output, restricting the model's privileges to the minimum it needs, requiring human approval for high-risk actions, separating and marking untrusted external content, and regular adversarial testing.
NIST reports that current models remain highly vulnerable to direct prompt injection. Some mitigations therefore work at the system level: deployers design AI systems on the assumption that a model with access to sensitive data, or with the ability to take undesirable actions, may leak that data or take those actions.
Similar Terms
2 termsSupply Chain Attack
Prompt injection works through the input combined with a model's prompt. An AI supply chain attack targets the dependencies an AI system is built from, such as data collection, third-party models, and third-party plugins, through data poisoning or model poisoning.
Least Privilege
Least privilege is a mitigation for prompt injection rather than a related attack. OWASP recommends restricting the model's access privileges to the minimum necessary for its intended operations, which limits what an injected instruction can reach.
Frequently Asked Questions
What is the difference between direct and indirect prompt injection?→
In a direct prompt injection, the user's own prompt input alters the model's behavior. In an indirect prompt injection, the model takes input from external sources, such as websites or files, that contain content which alters its behavior when the model interprets it. A third party mounts an indirect injection, and the model's primary user is often the one harmed.
What is the difference between prompt injection and jailbreaking?→
Jailbreaking is a form of prompt injection in which the inputs cause the model to disregard its safety protocols entirely. Prompt injection is the broader category of inputs that manipulate a model's responses and alter its behavior.
Can prompt injection be fully prevented?→
Not reliably. OWASP states that it is unclear whether fool-proof methods of prevention exist, and NIST reports that current models remain highly vulnerable to direct prompt injection. Defenses aim to limit the impact, for example by giving the model the minimum privileges it needs and requiring human approval for high-risk actions.
Does retrieval augmented generation (RAG) prevent prompt injection?→
No. According to OWASP, research shows that techniques like retrieval augmented generation (RAG) and fine-tuning do not fully mitigate prompt injection vulnerabilities.
Related
Tool categories
Glossary terms
Sources
Definitions follow the government and standards body sources listed above. This site is not affiliated with the agencies or organizations cited.