liveBook · Manning

Chapter 7: Contextual prompting

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

The chapter introduces contextual prompting as using information inside a prompt to guide a model’s behavior for a specific request.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces contextual prompting as using information inside a prompt to guide a model’s behavior for a specific request.

Key terms: contextual prompting

7.1 In-context learning

This section explains how a model adapts to instructions or examples within a single prompt, and why that is different from fine-tuning.

Key terms: in-context learning, next-token prediction, current context window, training distribution, zero-shot prompting, few-shot prompting, input–output examples, local pattern, fine-tuning, prompt-level adaptation

7.2 Zero-shot prompting

This section defines zero-shot prompting, explains why it is a useful default, and shows when inconsistent results warrant adding examples.

Key terms: zero-shot prompting, task instructions, pretraining data, token cost, training distribution, proprietary categories, organization-specific conventions, few-shot prompting, domain fit

7.3 Few-shot prompting

This section explains when to add input–output examples to a prompt and how to use a small number of them effectively.

Key terms: few-shot prompting, input–output examples, zero-shot prompting, output consistency, classification tasks, category definitions, system prompt, few-shot examples, user prompt, one or two examples

7.3.1 Practical example 1: CI pipeline failure handoff generation

A CI failure example compares a useful but prose-shaped zero-shot handoff with a few-shot handoff that follows the team’s four-field triage pattern.

Key terms: zero-shot, few-shot, Reference Examples, four-field handoff pattern, Deployment rollout, readiness probe, smoke tests, Next step

7.3.2 Format consistency

This section shows how consistent value formats across few-shot examples make the model’s output more predictable and easier to parse.

Key terms: few-shot prompt, reference examples, Classification: field, value shapes

7.3.3 Example selection

This section explains how to choose and evaluate a small set of few-shot examples so they cover important patterns without becoming narrow or costly.

Key terms: content diversity, edge case coverage, boundary case, realistic input quality, label coverage tradeoffs, common case, omitted labels, example count, example ordering, order bias

7.3.4 Advanced variations

This subsection briefly identifies three advanced ways to extend few-shot prompting with contrasting examples, reasoning steps, or retrieved examples.

Key terms: contrastive few-shot prompting, few-shot chain of thought, few-shot retrieval-augmented generation

7.3.5 Hands-on practice

This hands-on section asks readers to compare zero-shot and few-shot prompts for engineering tasks, testing how formatting, example selection, and token cost affect the design.

Key terms: zero-shot baseline, few-shot examples, task inputs, format consistency, strict repeated formatting, output structure, representative example, boundary example, label coverage, edge case coverage

7.4 Summary

This summary contrasts prompt-time adaptation with fine-tuning and recaps when and how to use few-shot prompting.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Prompt types Chapter 8: Prompt sampling →

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.