liveBook · Manning

Chapter 10: Security

What you will learn in chapter 10 of Prompt Engineering in Practice

This introduction shows how a user message can cause a tested chatbot to expose customer data and frames prompt design as a security concern.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction shows how a user message can cause a tested chatbot to expose customer data and frames prompt design as a security concern.

Key terms: system prompt, prompt, prompt security, prompt design, attack surface, structural boundaries, precisely constrained prompt

10.1 Why prompts are attackable

Explains why prompts are attackable: the model processes trusted instructions and externally supplied text together, so either can influence its output.

Key terms: single continuous sequence, privilege hierarchy, trusted and untrusted regions, trusted input, untrusted input

10.1.1 Practical example 1: The unguarded prompt

An incident-summary example shows how an instruction hidden in pasted ticket text can redirect a model, and how delimiters plus explicit trust framing change its response.

Key terms: injected instruction, authoritative update, structural basis, trust framing, delimiter markers, external content, data, directives

10.2 Prompt injection

Defines prompt injection, explains why untrusted instructions can redirect a model, and identifies where those instructions can enter and how delimiters help separate them.

Key terms: prompt injection, untrusted input, developer’s instructions, flat-sequence problem, structural separation, authoritative phrasing, delimiter-based separation, trusted and untrusted regions, potential vector

10.2.1 Practical example 1: The support chatbot

The support chatbot example contrasts a successful prompt injection with a revised prompt that treats customer messages as untrusted queries and returns a defined fallback.

Key terms: system prompt, prompt injection, user input, delimiter markers, trust-framing instruction, fallback, customer message

10.2.2 Practical example 2: The injected document

A knowledge-base assistant example shows how instructions hidden in a retrieved document can hijack a summary, and how document scoping keeps that content in the role of source material.

Key terms: retrieved content, external content, untrusted input, injected content, system administrator message, document scoping, [DOCUMENT START], [DOCUMENT END], external source material

10.3 Jailbreaking and instruction conflict

This section distinguishes jailbreaking from prompt injection and instruction conflict, explains how ambiguous or competing instructions create openings for attackers, and identifies precise wording as the main defense.

Key terms: jailbreaking, hypothetical framing, persona substitution, gradual turn-by-turn escalation, prompt injection, role assignment, qualitative phrases, ambiguous guidance, instruction conflict, system prompt

10.3.1 Practical example 1: The code review assistant

The code review assistant example shows how a vague refusal rule can fail under a roleplay jailbreak and how a closed-world prompt with a fixed fallback handles the same request.

Key terms: inappropriate requests, adversarial framing, roleplay, helpfulness, closed-world approach, code review, alternate personas, fixed fallback

10.3.2 Practical example 2: The policy chatbot

An HR chatbot example shows how a broad helpfulness instruction can undermine a privacy rule, and how explicit scope and fallback behavior resolve the conflict.

Key terms: instruction conflict, helpfulness, privacy constraint, company-wide policies, individual employee information, fallback, qualitative safety language, precise constraints, adversarial pressure

10.4 Prompt-hardening techniques

The section explains five complementary prompt-hardening techniques and how to review and test them before deployment.

Key terms: delimiter-based separation, explicit trust framing, untrusted content, closed-world instruction sets, defined scope, out-of-scope requests, explicit fallback instructions, out-of-scope, constraint, minimal context exposure

10.4.1 Practical example 1: Hardening a deployment notification bot

This example hardens a deployment notification prompt in stages so untrusted payloads remain data, the bot stays within its task, and unnecessary fields never reach the model.

Key terms: deployment payload, untrusted, hardening, delimiter-based separation, explicit trust framing, [PAYLOAD START], [PAYLOAD END], closed-world instruction set, explicit fallback, deployment notification

10.4.2 Practical example 2: Hardening a ticket triage prompt

This example shows how an injected instruction in a customer ticket can derail triage, and how trust framing and a tightly restricted output format work together to resist it.

Key terms: untrusted input, injected classification, system prompt, trust framing, [TICKET START], [TICKET END], ticket content, closed-world instruction set, strict output format, output space

10.5 The limits of prompt-only security

This section explains why prompt hardening reduces security risk but cannot guarantee compliance, especially under sustained attacks, sensitive context exposure, or model changes.

Key terms: probabilistic system, system instructions, prompt-level defenses, persistent adversarial pressure, multiturn attacks, conversation history, sensitive data in context, context window, minimal context exposure, model compliance variance

10.5.1 Practical example 1: When the prompt fails

A hardened handbook assistant gradually moves beyond its intended scope, showing where prompt hardening ends and system-level defenses become necessary.

Key terms: system prompt, handbook content, structural defenses, persistent adversarial pressure, fallback instruction, multiturn behavioral drift, scope expansion, prompt-only security, system-level response, turn-by-turn output evaluation

10.5.2 Hands-on practice

This hands-on section asks readers to revise vulnerable prompts, test whether the revisions preserve legitimate behavior, and identify risks that prompt changes alone cannot address.

Key terms: injection vector, delimiter-based separation, explicit trust framing, qualitative constraint language, behavioral rule, closed-world instruction set, instruction conflict, explicit fallback, minimal context exposure, retrieved API specification

10.6 Summary

The chapter summary distinguishes structural and interpretive prompt attacks, recaps prompt-level hardening techniques, and identifies where better prompts are insufficient.

Concepts explained in this chapter

← Chapter 9: Advanced prompt patterns Chapter 11: Managing prompts in production →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.