DSPy tutorial: signatures, evals and prompt optimization
Learn DSPy signatures and judge-first optimization through a text rewriting example, with reported judge accuracy rising from 80% to 20 of 20 examples.
Player not loading? Watch on YouTube
Mike Taylor, Compound's Drew and DSPy maintainer Isaac work through a notebook tutorial on context engineering. They explain how DSPy separates a task's typed inputs and outputs, called a signature, from the model and inference strategy used to complete it. The example combines a text humanizer with an AI-text detector using Python modules and Predict calls.
The practical focus is evaluation. Taylor loads labeled human and AI writing from a CSV, splits the data for training and testing, and measures the detector against known answers. He then uses that detector as an LLM judge for the rewriting task. The walkthrough reports an initial judge accuracy of 80% and a humanizer score of 10% against the original judge.
The saved optimization results first show an improved judge, which Taylor reports gets 20 of 20 examples correct. The optimization is not rerun live because of the time required. He then uses the optimized judge to improve the humanizer, reporting a 70% score. These are results on the example data and its chosen evaluator, rather than evidence of reliable AI-text detection in general.
The discussion also covers structured outputs, model switching and best-of-N selection. Isaac explains RLMs as a strategy that uses Python code and subagents, then describes DSPy Flex as a way to explore alternative task implementations. The tutorial uses model APIs; it does not demonstrate how to run models locally.