liveBook · Manning

Prompt engineering

As explained in The AI Pocket Book

The practice of designing prompts to steer a language model toward better or more reliable outputs.

Prompt engineering is the practice of designing prompts that steer a language model toward more useful, accurate, or customized outputs. It is usually the first improvement to try before changing the model itself. section 2.13 section 3.4

A worked example

A prompt asks: “Roger has 5 tennis balls. He buys 2 cans with 3 balls each. How many does he have?” It first demonstrates: “2 cans of 3 is 6; 5 + 6 = 11.” A similar apple problem follows. Including these intermediate steps helped the model solve the second problem correctly, while omitting them produced an incorrect answer. section 2.13

Common prompt-engineering moves include:

  • Add a few demonstrations of the desired task, called few-shot prompting, to remove ambiguity about format or content. section 3.3
  • Show intermediate reasoning steps when a task benefits from a demonstrated solution path; this is commonly called chain-of-thought prompting. section 2.13
  • Supply additional context through retrieval-augmented generation (RAG), especially when the model can use a large context window. section 3.3
  • Include reference images when customizing image generation, such as indicating a desired style in Midjourney. section 3.3

Prompt engineering improves an off-the-shelf model without changing its internal parameters. Richer prompts can make a general model more adaptable, but results depend on model capability and available context space. It is not a guarantee against hallucinations. section 3.3 section 3.4

Table 3.2 Off-the-shelf vs. fine-tuned AI

Off-the-shelf AIBest when . . .

Fine-tuned AIBest when . . .

• Prompt engineering techniques work well.

• It is okay to use proprietary AI.

• You can afford large models.

• You prioritize ease of use.

• You want highly customized outputs, and you’ve exhausted other options.

• You need to use smaller models (for example, for self-hosting them).

• You have ML expertise and access to computing resources.

Compare prompt-based customization with fine-tuning when choosing between ease of use, customization, model size, proprietary systems, and self-hosting. section 3.4

How The AI Pocket Book covers it

How deep it goes
Demonstrates few-shot and chain-of-thought prompting, then compares prompting with fine-tuning without detailing model internals.
Examples
Uses arithmetic word problems, world-record tables, RAG context, and Midjourney image references as concrete examples.
What it assumes
Assumes familiarity with language models and generative AI, while defining prompting techniques through concrete examples.
What you can do after
Apply prompting through demonstrations, reasoning examples, retrieved context, and reference images before attempting fine-tuning.
How it connects
Connects prompt engineering with hallucinations, chain-of-thought prompting, few-shot prompting, RAG, and fine-tuning.

Also explained in

Compare how 38 books explain prompt engineering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The AI Pocket Book. The section links point to the parts of the book it draws on.