DSPy separates program logic from prompt text, enabling automated prompt optimization. These exercises cover Signature declarations, ChainOfThought vs. Predict, optimizers like BootstrapFewShot, ReAct for tool use, and how DSPy's programming model differs from traditional prompt engineering.
0 / 5 completed
1 / 5
What is a DSPy Signature and how is it used?
A DSPy Signature is a declarative specification like class QA(dspy.Signature): question: str -> answer: str that describes what a module takes as input and produces as output. DSPy uses signatures to auto-generate prompts and to guide optimizers in finding better prompt formulations without manual prompt engineering.
2 / 5
A developer uses dspy.ChainOfThought('question -> answer'). What does this module add compared to dspy.Predict('question -> answer')?
dspy.ChainOfThought automatically adds a reasoning output field to the signature and instructs the model to think step-by-step before producing the final answer. This mirrors chain-of-thought prompting but is handled declaratively by DSPy rather than requiring manual prompt construction.
3 / 5
What is the role of a DSPy Teleprompter/Optimizer like BootstrapFewShot?
DSPy optimizers (formerly called teleprompters) automatically improve a DSPy program's prompts by searching for better few-shot examples, instructions, or both. BootstrapFewShot runs the program on training examples, collects successful traces, and uses them as few-shot demonstrations, all without manual prompt writing.
4 / 5
A DSPy program needs to call a custom Python function during inference. Which DSPy construct enables this?
dspy.ReAct implements an agent loop that can call external tools. You define tools as Python functions and pass them to ReAct, which instructs the LLM to select and invoke tools iteratively until it can answer the query. This enables DSPy programs to interact with APIs, databases, or computation tools.
5 / 5
How does DSPy's programming model differ from traditional prompt engineering?
DSPy separates program logic (what to compute) from prompt text (how to instruct the model). You write Python code using DSPy modules and signatures; the actual prompt strings are generated and optimized automatically. This means improving a program means adjusting the logic or providing better training examples, not rewriting prompts manually.