prompt injection
Prompt injection is an attack where adversarial input is designed to steer a model or model-powered app into ignoring its original instructions and performing unintended actions. These actions can include leaking secrets, executing unsafe steps, or following attacker-supplied goals.
The injected content doesn’t have to be visible or readable to a human, as long as the model parses it. Injection is usually deliberate, but a user can also trigger it inadvertently by supplying input that the model reads as an instruction.
Variants include direct prompt injection, where malicious instructions are entered through the model interface. Indirect prompt injection hides instructions in retrieved or linked content that the system ingests during workflows like RAG or tool use.
Multimodal injection is a growing third surface, where the payload hides in an image, audio, or another non-text modality that a multimodal model processes alongside benign text. Prompt injection exploits the lack of a strict boundary between instructions and data.
Mitigations should adopt a defense-in-depth approach, including:
- Input and output filtering and sanitization
- Isolating and clearly delineating system and user instructions
- Enforcing least-privilege access for tool integrations and sandboxes
- Requiring human-in-the-loop approval for high-risk or privileged actions
- Implementing allow or deny lists for tool use
- Verifying the provenance or trustworthiness of external content
- Hardening retrieval pipelines
- Monitoring and conducting adversarial testing to detect residual risks
Related Resources
Tutorial
Prompt Engineering: A Practical Example
Learn prompt engineering techniques with a practical, real-world project to get better results from large language models. This tutorial covers zero-shot and few-shot prompting, delimiters, numbered steps, role prompts, chain-of-thought prompting, and more. Improve your LLM-assisted projects today.
For additional information on related topics, take a look at the following resources:
- Building Type-Safe LLM Agents With Pydantic AI (Course)
- Build an LLM RAG Chatbot With LangChain (Tutorial)
- How to Add Features to a Python Project With Codex CLI (Tutorial)
- Practical Prompt Engineering (Quiz)
- First Steps With LangChain (Course)
- Build an LLM RAG Chatbot With LangChain (Quiz)
- Use Codex CLI to Enhance Your Python Projects (Course)
- How to Add Features to a Python Project With Codex CLI (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 17, 2026