Skip to content
47% off: the complete course for $79 (reg. $149)Order now →
AI Builder

AI builder glossary

Prompt injection

An attack where text the model reads, from a user or from documents, emails, or web pages, carries instructions that override what the developer intended.

Prompt injection exploits the fact that a model can't reliably tell instructions from data. Anything you place in its context, such as a customer message, a retrieved help article, an uploaded PDF, or a fetched web page, can contain text telling it to ignore previous instructions and do something else, and the model may comply. Direct injection comes from the user typing it; indirect injection hides in content the feature pulls in.

The impact depends on what the feature can do. For a summarizer, the worst case may be a misleading summary. For features that call tools, write data, or render links and images, injection can leak private data, trigger actions, or exfiltrate information through a crafted URL. The dangerous combination, which Simon Willison named the lethal trifecta, is private data the model can reach, untrusted content it reads, and any channel through which data can leave.

No prompt reliably prevents injection, so defend with architecture. Give the model only the tools and data the current user is allowed to access, require confirmation for consequential actions, mark untrusted content clearly with delimiters, allowlist links and images in output, and avoid completing the trifecta in any single call. Then red-team the feature with planted instructions to check the defenses hold.

Example

A customer emails Deskmate support with hidden text instructing the assistant to include other customers' email addresses in its reply. Because the drafting step can only see the current ticket and every draft is reviewed before sending, the attack has nothing to reach.

Learn more in the course

Related terms

Go from definitions to doing

Learn to build AI-powered apps in 132 practical lessons.