dspy-output-refinement-constraints

Solid

This skill should be used when the user asks to "refine DSPy outputs", "enforce constraints", "use dspy.Refine", "select best output", "use dspy.BestOfN", mentions "output validation", "constraint checking", "multi-attempt generation", "reward function", or needs to improve output quality through iterative refinement or best-of-N selection with custom constraints.

AI & Automation 78 stars 10 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 90/100

Stars 20%
63
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# DSPy Output Refinement & Constraints ## Goal Improve output quality using iterative refinement (dspy.Refine) and best-of-N selection (dspy.BestOfN) with custom constraint validation. ## When to Use - Outputs need format validation (JSON, specific structure) - Length constraints (max tokens, word count) - Content requirements (must include X, avoid Y) - Quality improvement through multiple attempts - Replacing deprecated Assert/Suggest patterns ## Related Skills - Design signatures: [dspy-signature-designer](../dspy-signature-designer/SKILL.md) - Optimize programs: [dspy-miprov2-optimizer](../dspy-miprov2-optimizer/SKILL.md) - Evaluate quality: [dspy-evaluation-suite](../dspy-evaluation-suite/SKILL.md) ## Inputs | Input | Type | Description | |-------|------|-------------| | `module` | `dspy.Module` | Module to refine | | `reward_fn` | `callable` | Constraint validation function | | `N` | `int` | Number of attempts | | `threshold` | `float` | Minimum reward to accept | ## Outputs | Output | Type | Description | |--------|------|-------------| | `refined_output` | `dspy.Prediction` | Validated, refined result | ## Workflow ### Phase 1: dspy.Refine for Iterative Improvement Refine iteratively improves outputs across multiple attempts: ```python import dspy dspy.configure(lm=dspy.LM("openai/gpt-4o-mini")) # Base module summarizer = dspy.ChainOfThought("document -> summary: str") # Reward function: checks constraints def summary_reward(args, pred): summary =...

Details

Author
OmidZamani
Repository
OmidZamani/dspy-skills
Created
5 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category