liveBook · Manning

Chapter 1: Introduction to prompt programming and DSPy

What you will learn in chapter 1 of Building LLM Applications with DSPy

This introduction explains why manual prompt tuning is difficult and how DSPy replaces it with a code-based, evaluable approach to prompt programming.

After this chapter you will be able to

Section by section

Introduction

This introduction explains why manual prompt tuning is difficult and how DSPy replaces it with a code-based, evaluable approach to prompt programming.

Key terms: prompts, prompt engineering, trial-and-error, prompt programming, DSPy, evaluating, optimizing, candidate prompts

1.1 What makes prompt programming different?

This section frames prompt programming as a higher-level evolution of manually developing prompts.

Key terms: prompt programming, manually developing prompts, higher-level concepts, lower-level details

1.1.1 The goals of prompt programming

This section presents prompt programming as a higher-level way to specify an LM application and lists the goals of tools such as DSPy.

Key terms: prompt programming, top layer, LM’s API, higher-level code, prompt quality, development time, re-execution of prompt development code, LMs, prompting techniques

1.1.2 Prompt programming vs. prompt engineering

This section contrasts the difficulties of manually engineering prompts with DSPy’s methodical approach to generating, evaluating, and selecting prompts.

Key terms: prompt engineering, manually creating and tuning prompts, LMs, DSPy, prompt programming, prompt optimization, candidate prompts

1.2 Introducing DSPy

This section explains what DSPy stands for and how its name reflects its approach to language models.

Key terms: DSPy, Declarative Self-improving Python, declarative, self-improving, optimization process

1.2.1 DSPy code example

This section uses a short question-answering example to show how DSPy organizes LM work as clear, interchangeable code rather than handwritten prompts.

Key terms: LM, question answering, prompts, inputs and outputs, testing, debugging, code reviews, monitoring in production, modularity, Predict module

1.2.2 Advantages of working with code

This section explains why treating prompts as source code can make LLM application development more disciplined and reliable.

Key terms: source code, prompt engineering, prompt programming, clean, readable, testable, and modular

1.2.3 A methodical search for optimal prompts

The section explains why finding better prompts through ad hoc experimentation is slow and why apparent improvements need rigorous testing.

Key terms: heuristics, prompting techniques, search space, optimal prompts, ad hoc, small test sets, test rigorously

1.2.4 The bitter lesson

The section applies AI’s “bitter lesson”—that computational search and learning tend to outperform hand-coded expertise—to the development of prompts.

Key terms: the bitter lesson, general methods, computation, domain knowledge, prompt engineering, automated system, search and learn

1.2.5 A data-driven approach to tuning prompts

The section explains why reliable prompt comparison requires repeated testing and how DSPy makes that testing a reusable, data-driven process.

Key terms: optimal prompt, inputs, stochastic, prompt programming, test data, evaluation function, candidate prompts

1.2.6 Adapting to change

The section explains why LM applications need to adapt after launch and how DSPy can reduce the cost of updating their prompts.

Key terms: LM, prompts, edge cases, prompt engineering, DSPy, retune the prompts automatically

1.2.7 Making the best use of LMs

The section explains how automated prompt search can make smaller language models practical despite their sensitivity to prompts.

Key terms: smaller LMs, prompts, long-term costs, prompt programming, DSPy, optimal prompt

1.3 Working with complex LM-based applications in DSPy

This section explains why complex LM applications are difficult to tune manually and how DSPy helps compose and optimize their workflows.

Key terms: prompt tuning, LM calls, query costs, control flows, modular organization, workflows, automatically optimize, set of prompts, overall results, reliable prompts

1.4 Where is DSPy useful?

This section explains when DSPy is worth using and when direct prompting may be sufficient.

Key terms: DSPy, prompt programming, LM requests, directly prompting, manually created prompts

1.5 Working with LangChain

This section compares LangChain and DSPy, explaining their overlap, their different approaches to prompts and workflows, and when using both may help.

Key terms: LangChain, DSPy, prompts, workflows, LangGraph, plain Python, pipelines

1.6 Building LLM applications through baselines and optimization

This section presents a DSPy development workflow: build a simple baseline, evaluate it, optimize prompts if needed, and deploy when the application is satisfactory.

Key terms: baseline, evaluation, optimizing, prompts, production

1.7 What this book covers

The section outlines the book’s coverage and explains that real-world datasets support its emphasis on evaluation and iterative improvement.

Key terms: real-world datasets, evaluating, iterative improvements, reliable systems

1.8 Summary

Where this is used later

Concepts explained in this chapter

Chapter 2: Basic prompting and DSPy →

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.