Skip to main content
Interactive 3D/DSPy - Automatic Prompt Optimization
DSPy Pipeline
DSPy Program
Teleprompter / Compile
Bootstrap Few-Shot
Optimized Program
Accuracy over bootstrap iterations
+36.5% gain
50%60%70%80%90%manual prompt
iteration 1iteration 4
Manual Prompt
Answer the question.
Q: {question}
A:
Score: ~54%
DSPy-Optimized Prompt
Given the context, answer the question accurately and concisely.

Examples:
{few_shot_examples}

Context: The task is {task_description}.
Q: {question}
A: Let me think step by step.
Score: ~89%
Controls
Metric
Bootstrap samples16
432
Optimizer
DSPy (Khattab et al., 2023) treats prompts as learnable parameters. Instead of writing prompts manually, you define a pipeline in Python and a compiler optimizes the prompts using your metric.
Gain summary:
Initial: ~53%
Final: ~89%
Gain: +36.5pp

DSPy - Automatic Prompt Optimization - Interactive Visualization

DSPy (Khattab et al., 2023) reframes prompt engineering as program optimization. Instead of hand-crafting prompts, you define a pipeline using Python modules (Predict, ChainOfThought, ReAct) and a metric function. The DSPy compiler (Teleprompter) runs the pipeline on training examples, collects successful traces, and bootstraps few-shot demonstrations that maximize your metric - automatically discovering better prompts than humans typically write.

  • Pipeline diagram: Program → Teleprompter/Compile → Bootstrap → Optimized Program with clickable stage descriptions
  • Animated optimization curve showing metric improvement over bootstrap iterations vs manual prompt baseline
  • Accuracy vs F1 metric toggle and bootstrap samples slider (4–32) showing how more data improves the optimizer
  • Side-by-side comparison of manual prompt vs DSPy-optimized prompt structure with quality scores

Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.