liveBook · Manning

Predict

As explained in Building LLM Applications with DSPy

Predict is a DSPy module that represents a basic prompting operation for invoking a language model.

Predict is DSPy’s basic prompting module. Give it a signature describing input and output fields; once instantiated, it becomes a callable program that builds a prompt, calls a language model, and returns the requested outputs. section 2.2 section 3.3.2

Listing 2.2 Question-answering example
import dspy
OPENAI_API_KEY = . . .
lm = dspy.LM(model='gpt-4o-mini', api_key=OPENAI_API_KEY)
dspy.configure(lm=lm)
prog = dspy.Predict("question -> answer")
prediction = prog(question="What is the capital of France?")
print(prediction)

A minimal question-answering program shows how to instantiate Predict with a signature and call it with an input. section 2.2

A Predict program can serve as a starting point for different tasks:

  • For question answering, map a question to an answer. section 2.2
  • For intent classification, pass a message and candidate labels, then receive an intent label. Calling the program for each test message requires a language-model call each time. section 3.3.2

Predict provides a baseline rather than optimizing the prompt by itself. Its modular interface makes it possible to change prompting techniques or language models without rewriting the surrounding application; account for call and token costs when running it over many inputs. section 2.2 section 3.3.2 section 1.2.1

How Building LLM Applications with DSPy covers it

How deep it goes
Explains signature-based construction and calls, but stops short of prompt optimization.
Examples
Demonstrates question answering and intent classification, including inference over test messages.
What it assumes
Assumes a configured language model and a signature specifying input and output fields.
What you can do after
Build it from scratch: define a signature, instantiate Predict, and call the program with matching inputs.
How it connects
Connects signatures, language models, DSPy programs, and prompt optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building LLM Applications with DSPy. The section links point to the parts of the book it draws on.