Prompt Injection Explained: Direct, Indirect and Why Guardrails Alone Aren't Enough

How prompt injection works in LLM applications, why indirect injection through retrieved content is the bigger risk, and the layered controls that reduce impact.

By the iDefenzer Security Team

Prompt injection is the most widely discussed risk in LLM application security, and it sits at the top of the OWASP Top 10 for LLM Applications. The core problem is simple: a language model receives instructions and data in the same channel, natural-language text, and has no reliable way to tell them apart.

Direct prompt injection

In a direct attack, the user types instructions intended to override the system prompt: asking the model to ignore previous rules, adopt a different persona or reveal its configuration. Jailbreaks are a well-known example. Direct injection matters, but the attacker can usually only affect their own session.

Indirect prompt injection

Indirect injection is more dangerous. Here, the malicious instructions are hidden in content the model processes on someone else's behalf: a web page it summarises, an email it triages, a PDF in a knowledge base or a support ticket. When a victim asks the assistant to process that content, the attacker's instructions execute with the victim's context and permissions.

Why it mattersIf an assistant can read a mailbox and send email, an injected instruction in one incoming message may cause it to forward sensitive data, with no exploit code involved.

Why guardrails alone are not enough

Input filters and moderation models catch many known payloads, but attackers can rephrase, encode, split instructions across turns or hide them in formatting. Because there is currently no complete technical fix for prompt injection, defence needs to focus on limiting what a successful injection can achieve.

Controls that reduce impact

  • Least-privilege tools: give agents only the functions and data scopes a task needs, using the end user's permissions rather than a powerful service account.
  • Human approval for sensitive actions: require confirmation before sending messages, moving money or changing records.
  • Treat model output as untrusted: validate and encode output before it reaches browsers, shells, SQL or downstream APIs.
  • Segregate untrusted content: clearly mark retrieved data and limit what instructions inside it can trigger.
  • Monitor and test continuously: log tool calls, alert on unusual patterns and keep an adversarial test set for regression testing.

Testing for prompt injection

Effective testing goes beyond trying a list of jailbreak prompts. It maps every source of content the model can read, every action it can take and every place its output is used, then attempts to connect an attacker-controlled input to a harmful outcome. That end-to-end view is where the real risk becomes visible.

Related serviceNeed help with this? Our AI & LLM Security team can help you assess and reduce this risk. Talk to us.
Start a conversation

Your Security Posture Deserves More Than a Checklist.

Let's identify your security gaps, understand your risks and build a stronger security strategy.