Prompt injection is a class of attacks or unintended interactions in which instructions supplied through user input or external content cause a language model to depart from the application’s intended behavior. It can be direct in the prompt or indirect in documents, web pages, messages and tool results.

Language models process instructions and data through the same language channel. A sentence inside a retrieved document may compete with the system’s task, and the model cannot provide a deterministic security boundary between them. The consequence becomes serious when the application gives the model secrets, broad tools or authority to act.

Prompt injection is not solved by a stronger warning in the system prompt. Assume the model can be influenced and design the surrounding system so a manipulated output cannot exceed the user’s permission, disclose unnecessary data or execute a high-impact action without policy and approval.

Indirect prompt injection turns ordinary content into an instruction channel

Direct injection appears in the user’s message, such as a request to ignore prior constraints. Indirect injection is embedded in content the application later reads: a webpage, PDF, support ticket, calendar event or retrieved knowledge article. The user may never see the malicious instruction.

An agent amplifies the risk because it can act on the influenced interpretation. A page might tell a browsing agent to send data elsewhere or call a tool with altered arguments. Content provenance and instruction hierarchy help reasoning, but actual safety comes from limiting data and authority outside the model.

Injection surface and system control
SurfaceExamplePrimary system control
User inputInstruction to override taskCapability and output boundary
Retrieved documentHidden action requestUntrusted-content handling
Tool resultMalicious text from external APISchema and provenance
MemoryPersistent hostile instructionWrite policy and isolation
Model outputGenerated command or markupDownstream validation

Design for a model that may follow the wrong instruction

Instructional defenses can reduce attacks and improve normal behavior, but they are probabilistic. The hard controls are familiar security engineering: least privilege, authorization, data minimization, isolation, validated interfaces, confirmation, monitoring and incident response.

Apply controls according to consequence. A drafting tool with no secrets or external action has a smaller impact surface than an agent that can email, purchase or change records. Increase review and sandboxing with authority, and keep a deterministic stop between model recommendation and irreversible effect.

  • Never rely on the prompt as the authorization layer.
  • Keep secrets out of model-readable context.
  • Treat retrieved and tool-returned text as untrusted.
  • Validate in the component that executes or renders output.
  • Test side effects, not just conversational refusal.

Useful outcomes from prompt injection

  • Untrusted content is explicitly identified across every model input path.
  • Secrets and unnecessary sensitive context are kept out of model prompts.
  • Tool authorization is enforced outside the model for each call.
  • High-impact actions require deterministic checks and confirmation.
  • Attack tests measure both model response and downstream side effects.

How to run the work

  1. 01

    Map instruction and data channels

    Inventory system instructions, user messages, retrieved files, web content, emails, memory and tool results. Mark trust, owner and permission for each. Treat data controlled by a customer, third party or prior model output as untrusted even when it appears inside a business document.

  2. 02

    Reduce accessible authority

    Do not place reusable secrets in prompts. Give tools narrow operations and minimum privileges, apply authorization at execution and scope access to the current user and resource. Separate read, draft and act capabilities so a content-processing task cannot silently become an external action.

  3. 03

    Constrain and validate effects

    Use structured tool schemas, allowlists, input validation, output encoding and transaction controls. Show material action details to the user before confirmation. Validate model-produced URLs, code, queries and markup in the receiving system rather than trusting the model to sanitize itself.

  4. 04

    Test realistic attack paths

    Place adversarial instructions in user prompts, documents, metadata, web pages and tool output. Test data exfiltration, goal redirection, tool misuse and multi-step persistence. Record whether a control prevented the effect, not whether the model refused in natural language.

Questions that change the decision

  • Which model inputs can an untrusted actor influence directly or indirectly?
  • What data and tools are unnecessary for the current task?
  • Where is authorization enforced when the model requests an action?
  • Which output becomes executable, rendered or externally transmitted?
  • What human confirmation is meaningful before a material side effect?

Where teams lose control

01

A retrieved document can contain instructions that redirect an agent.

02

Prompt secrecy creates false confidence because model context can leak.

03

An overprivileged tool converts generated text into unauthorized action.

04

Model output can inject code or commands into a downstream interpreter.

05

A memory store can preserve malicious instructions across later sessions.

Measure the finished job

Measure the completed workflow, including review effort and exceptions. Output volume on its own is not evidence of a better process.

  • attack scenarios blocked before material effect
  • unauthorized tool requests denied by policy
  • sensitive fields exposed to the model per task
  • high-impact actions requiring valid confirmation
  • unsafe output rejected by downstream validation
  • prompt-injection regression coverage by input channel

Common questions

What is prompt injection?

Prompt injection occurs when user input or external content supplies instructions that cause a language model to depart from the application’s intended behavior.

What is indirect prompt injection?

It is an instruction embedded in content such as a document, webpage, email or tool result that the application later supplies to the model. The attacker may not interact with the model directly.

Can a system prompt prevent prompt injection?

It can reduce some behavior but is not a deterministic security boundary. Protect the system with least privilege, external authorization, data minimization, validated tools and approval for high-impact actions.

Is prompt injection the same as a jailbreak?

The terms overlap but are not identical in every taxonomy. Jailbreaking commonly targets model restrictions; prompt injection targets application instructions and can exploit external content and connected tools.

Primary references

Tony Kim

Tony Kim

Founder and CEO

Tony writes about applied AI, dependable product engineering and the systems that turn complex response work into controlled delivery.

AI product engineering for moving a software brief into a reliable production product.

Product leaders, founders and engineering teams. Start with the workflow, constraints and evidence you already have.

See Zeke