liveBook · Manning

Chapter 7: Prompt engineering: Becoming an LLM whisperer

What you will learn in chapter 7 of LLMs in Production

The introduction explains why prompting lets one general-purpose LLM serve many tasks and previews the chapter’s approach to prompt engineering.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why prompting lets one general-purpose LLM serve many tasks and previews the chapter’s approach to prompt engineering.

Key terms: prompt, prompt engineering, in-context learning, general-purpose tool, prompt engineering tooling, advanced prompting techniques

7.1 Prompting your model

This section defines prompting as crafting model input for a desired output and introduces prompt engineering as a way to make LLM application behavior more consistent without retraining.

Key terms: prompt, prompting, probable responses, parameters, retraining, prompt engineering, designing, templating, refining

7.1.1 Few-shot prompting

This section shows how a few examples can steer an LLM’s task and output format, while explaining the limits imposed by token budgets and cost.

Key terms: few-shot prompting, examples, sentiment analysis, instructions, JSON, XML, structured outputs, token limits, context limits, per token

7.1.2 One-shot prompting

The section explains how one-shot prompting uses a single example to guide an LLM, why it can work, and where it can fail.

Key terms: one-shot prompting, one-shot learning, instruction, example, pretraining, generalize, diminishing returns, bias, model size, task complexity

7.1.3 Zero-shot prompting

This section explains how zero-shot prompts can steer an LLM without examples, especially through reasoning cues, while emphasizing tradeoffs and model-specific results.

Key terms: zero-shot prompting, Q: [User’s Prompt] A:, Chain of Thought (CoT), think step by step, stopping criteria, thread of thought, GPT-4

7.2 Prompt engineering basics

This section distinguishes prompt engineering from casual prompting and explains when to try it before changing a model.

Key terms: prompt engineering, prompting, format, railings, finetuning, PEFT, LoRA, retrieval-augmented generation (RAG)

7.2.1 Anatomy of a prompt

This section breaks an application prompt into input, instruction, context, and system prompt, using an internal HR chatbot to show what each contributes.

Key terms: input, instruction, template, Q&A bot template, context, RAG, semantic search, few-shot, one-shot prompting, system prompt

7.2.2 Prompting hyperparameters

This section explains how generation settings beyond the prompt affect an LLM’s predictability, diversity, quality, and latency.

Key terms: prompt hyperparameter tuning, LLM API endpoint, temperature, logits, softmax, argmax, beam search, number of beams, latency, top K

7.2.3 Scrounging the training data

This section shows how inspecting a model’s training data can reveal effective wording, especially when prompt engineering is paired with finetuning.

Key terms: LAION, DreamBooth, base class, captions, Asian beauty, finetuning, prompt engineering, seed, recall

7.3 Tooling for structured outputs, workflows, and more

This introduction explains why applications that do more than wrap an LLM need prompt-engineering tools and sets up a look at prominent tools.

Key terms: prompt engineering, tools, function, personality

7.3.1 LangChain

This section introduces LangChain chains, shows how LCEL connects prompt, model, and parsing steps, and describes reusable chains and supporting tools.

Key terms: LangChain Expression Language, LCEL, chain, prompt template, parser, DAG, f-string prompt, RetrievalQA chain, RAG, LangServe

7.3.2 Guidance

This section introduces Guidance as a way to constrain LLM outputs and build reusable response rules, while distinguishing reliable output structure from accurate predictions.

Key terms: Guidance, prompt-and-pray, response space, stopping tokens, templating, guidance HF wrapper, grammars, @guidance decorator, parts-of-speech application, parts of speech prediction

7.3.3 DSPy

This section introduces DSPy as a way to program and optimize LLM prompting through defined tasks, modules, examples, and validation rather than hand-written prompt strings.

Key terms: DSPy, tool augmentation, retrieval, program prompting, signature, predictor, module, compile, validation metric, teleprompter

7.3.4 Other tooling is available but …

This section surveys other prompt-tooling projects and urges caution when choosing among them because the ecosystem is young and some projects have become inactive.

Key terms: sponsorship, open source projects, GitHub contribution, MiniChain, AutoChain, Promptify, Outlines, LangChain, Guidance

7.4 Advanced prompt engineering techniques

This section introduces tool access as a way to address missing or changing context that prompts alone cannot provide.

Key terms: training date, RAG, tools

7.4.1 Giving LLMs tools

This section explains how LLMs can call external tools, how prompting can add tools without finetuning, and what makes tool use difficult in practice.

Key terms: tools, API calls, Toolformer, <API></API>, inference, Guidance, finetune, string interpolation, tool inputs, error handling

7.4.2 ReAct

This section explains ReAct’s thought–action–observation loop and illustrates how an LLM can use tools through LangChain to answer questions that require multiple steps.

Key terms: Reasoning and Acting (ReAct), Thought, Action, Observation, Finish, few-shot, LangChain, OpenAI model, google-serper, serper.dev

7.5 Summary

This summary recaps how examples and prompt structure shape LLM requests, then distinguishes tools for building workflows, controlling output, and enabling tool use and reasoning.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Large language model services: A practical guide Chapter 8: Applications and Agents: Building an interactive experience →

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.