liveBook · Manning

Prompt injection

As explained in Introduction to Generative AI, Second Edition

A jailbreak prompt is an input crafted to make a generative model bypass restrictions or safety controls.

A travel-planning agent may read a webpage while arranging a trip. If that page contains a hidden instruction, the agent might follow it instead of the user’s request—even leaking information or taking an unsafe action. This is prompt injection: an attempt to manipulate a model’s behavior through instructions placed in user input or external data. section 8.20 section 5.11

Prompt injection is related to, but distinct from, jailbreaking. A jailbreak tries to trick a chatbot into bypassing its built-in safety constraints; an injection embeds malicious instructions in input or data to redirect its behavior. An attack may do both. section 5.11 section 8.22

Instructions can reach a model through different routes:

  • Direct injection uses a crafted user input to override safeguards or change the model’s behavior. section 10.10
  • Indirect injection places instructions in content the system reads, such as a webpage, document, or email. The user may be unaware that the content contains an instruction. section 8.20

A model’s prompt can combine system instructions, conversation history, external information, and the user’s latest request. Each can provide an avenue for manipulation if altered. Attackers may also use unusual formatting, hypothetical scenarios, or a sequence of requests that gradually approaches an unsafe topic. Results can be unpredictable, and strategies continue to change. section 5.9 section 10.10

Figure 5.12 A sample composition of an LLM prompt deployed in the chat context (e.g., ChatGPT, Claude, Gemini)
A close-up of several words

AI-generated content may be incorrect.

This diagram shows the different components that can make up a model’s prompt, including context and user input. section 5.9

A hidden instruction in a document

An agent processing a document may encounter an invisible instruction embedded in it. In a demonstrated zero-click exploit, simply reading such content can trigger malicious behavior without the user typing an attack prompt. Access to memory or tools can make the consequences more serious. section 8.22

Red teaming tests systems with adversarial inputs to uncover vulnerabilities, including unsafe responses and unintended tool use. Defenses must also address the surrounding system: limiting an agent’s available actions and requiring human approval for sensitive operations can provide a buffer, although deciding which actions are risky remains difficult. section 10.22 section 8.20

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Defines direct and indirect attacks and surveys strategies, consequences, testing, and safeguards without implementation detail.
Examples
Uses hidden webpage instructions, fictional hypotheticals, gradual requests, and invisible document content to illustrate attacks.
What you can do after
Evaluate and understand how injected instructions can redirect models and why agent action controls matter.
How it connects
Connects prompt injection with jailbreaking, red teaming, AI agents, tool use, and security safeguards.

Also explained in

Compare how 9 books explain prompt injection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Introduction to Generative AI, Second Edition. The section links point to the parts of the book it draws on.