TOPIC AI
DSPy compiling declarative prompt pipelines
IN 10 SECONDS
A framework by Stanford that replaces fragile manual prompt engineering by treating prompts as code programs, dynamically optimizing instructions and examples based on evaluations.
GOTCHA Compiling a DSPy program runs multiple training-like evaluation loops, generating high LLM API token spend.
HOW PROMPT COMPILATION FLOWS
01 Define signature declares inputs and outputs: class Qa(dspy.Signature): question -> answer.
02 Bootstrap optimizer dspy.teleprompt.BootstrapFewShot gathers training datasets.
03 Compile optimizer runs evaluations, optimizing prompt instructions and choosing best few-shot examples.
04 Save program saves optimized module weights configuration to disk for runtime execution.
POKE IT YOURSELF
python -c import dspy; lm = dspy.LM('openai/gpt-4o'); dspy.settings.configure(lm=lm) — bootstrap DSPy context
Drill this topic →
~70 sec read