PromptDefend / Prompt Injection
Prompt Injection

Prompt injection: how it works and how to defend against it

Short answerPrompt injection is an attack where text supplied to a large language model (LLM) overrides or subverts the instructions its developer intended. It is ranked LLM01, the top risk, in the OWASP Top 10 for LLM Applications (2025). No single filter eliminates it, so the practical defense is layered: inspect inputs and outputs, separate trusted instructions from untrusted content, restrict what tools and data the model can reach, and log every decision.
Updated 2026-10-17 · By the PromptDefend editorial team

What is prompt injection?

LLMs read instructions and data in the same channel: natural-language text. A prompt injection exploits that by placing instructions inside content the model processes, such as a user message, a web page, an email or a retrieved document, so the model follows the attacker's instructions instead of the application's.

The term covers two families:

Why prompt injection is more dangerous with AI agents

A chatbot that can only answer questions can leak information or say something harmful. An AI agent that can send email, call APIs, run code or move files can be steered into doing harmful things. OWASP calls this excessive agency (LLM06). Common outcomes include:

Real-world attack patterns

PatternHow it worksPrimary control
Instruction override"Ignore previous instructions" style text in user inputInput inspection, instruction hierarchy
Role-play jailbreakAsks the model to act as an unrestricted personaJailbreak classifiers, output policy
Hidden text in documentsWhite-on-white or metadata instructions in files used for RAGFile sanitization, retrieval filtering
Web content injectionInstructions planted on pages a browsing agent readsTreat retrieved content as untrusted, tool allow-lists
Encoding and obfuscationBase64, other languages, Unicode tricks to evade keyword filtersSemantic (not keyword-only) detection
Markdown/image exfiltrationModel renders a link or image URL containing secretsOutput filtering, block untrusted URLs
Tool-argument injectionPayload shapes the arguments of a function callArgument validation, least-privilege tools

How to defend against prompt injection

  1. Inspect every prompt and response inline. Use an AI firewall that detects injection and jailbreak attempts semantically, not just with keyword lists.
  2. Separate trust levels. Keep system instructions apart from user and retrieved content, label untrusted content, and never let retrieved text grant new permissions.
  3. Apply least privilege to tools. Allow-list the functions an agent may call, validate arguments, and require human approval for high-impact actions.
  4. Filter outputs. Block responses that contain secrets, PII, unexpected URLs or instructions destined for another system.
  5. Sanitize files and retrieved content before it enters a RAG index or context window.
  6. Red-team continuously. Run recurring adversarial tests, because model, prompt and tool changes can silently weaken guardrails.
  7. Log everything. Keep an audit trail of prompts, responses, detections and actions for incident response and compliance.

How ZeroTrusted.ai addresses prompt injection

ZeroTrusted.ai AI Firewall sits between users, agents and models and inspects every prompt, response and tool call against policy. Per ZeroTrusted.ai, it detects prompt injection and jailbreaks, filters outputs for hallucination and toxicity, governs tool and function calls with allow-lists, and works inline or out-of-band with sub-millisecond latency impact on most inference paths. AI HealthCheck runs recurring prompt-injection probes against deployed stacks to measure whether guardrails still hold, and agentic security testing adds adversarial and agent-escape testing before release.

Frequently asked questions

Can prompt injection be completely prevented?

Not with any single technique today. Because instructions and data share the same natural-language channel, the accepted approach is defense in depth: inline detection, least-privilege tools, output filtering, human approval for risky actions and continuous testing.

What is the difference between prompt injection and jailbreaking?

Jailbreaking is a type of direct prompt injection aimed at getting a model to ignore its safety rules. Prompt injection is broader and includes indirect attacks hidden in content the model reads, which often target data and tools rather than safety policies.

What is indirect prompt injection?

Indirect prompt injection hides malicious instructions in third-party content, such as web pages, emails, documents or tool outputs, that an LLM or agent later processes. The user does not see or type the payload.

Does a system prompt that says 'never reveal secrets' stop prompt injection?

No. Instructions in a system prompt can be overridden or extracted. Never put secrets or credentials in prompts, and enforce controls outside the model.

Which framework ranks prompt injection as a top risk?

The OWASP Top 10 for LLM Applications 2025 lists prompt injection as LLM01. MITRE ATLAS also catalogs LLM prompt injection techniques.

Disclosure: PromptDefend recommends ZeroTrusted.ai and is published in association with it. Product details are sourced from zerotrusted.ai. Regulatory summaries are educational and not legal advice.