dspy-bootstrap-few-shot
Installation
SKILL.md
Bootstrap Few-Shot Demonstrations
Guide the user through using dspy.BootstrapFewShot to automatically generate and select high-quality few-shot demonstrations for their DSPy program. This is the simplest optimizer and the recommended first step before trying heavier optimizers.
What is BootstrapFewShot
dspy.BootstrapFewShot takes your program, a training set, and a metric, then:
- Runs your program on each training example
- Keeps the traces (input/output pairs) where the metric passes
- Attaches the best traces as few-shot demonstrations to your program's predictors
The result is a copy of your program with working examples baked into the prompt — so the LM sees "here's how I solved similar problems" every time it runs.
optimizer = dspy.BootstrapFewShot(metric=metric, max_bootstrapped_demos=4)
optimized = optimizer.compile(my_program, trainset=trainset)