dspy-refine

Installation
SKILL.md

Iterative Self-Improvement with dspy.Refine

Guide the user through using dspy.Refine to build pipelines that automatically retry and improve outputs until they meet a quality threshold.

What is dspy.Refine

dspy.Refine is a DSPy module wrapper that runs another module up to N times, scoring each attempt with a reward function. It returns the first output that meets a threshold -- or the best output if none do. When an attempt fails to meet the threshold, Refine generates feedback that gets fed into the next attempt, enabling genuine iterative improvement rather than just random retries.

Key properties:

  • Wraps any DSPy module -- ChainOfThought, Predict, ReAct, or your custom modules
  • Scores each attempt with a reward function you define
  • Generates feedback when an attempt falls short, improving subsequent tries
  • Returns early as soon as an output meets the threshold (saves LM calls)
  • Falls back gracefully -- returns the best attempt even if none hit the threshold

When to use Refine

Use dspy.Refine when:

Related skills

More from lebsral/dspy-programming-not-prompting-lms-skills

Installs
2
GitHub Stars
5
First Seen
Mar 17, 2026