Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add OmidZamani/dspy-skills --skill dspy-output-refinement-constraintsgit clone --depth 1 https://github.com/OmidZamani/dspy-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-output-refinement-constraints)<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-output-refinement-constraints"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-output-refinement-constraints/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/omidzamani/dspy-skills/dspy-output-refinement-constraints"><img src="https://agentmods.dev/badge/skills/omidzamani/dspy-skills/dspy-output-refinement-constraints.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00035 | $0.01742 |
| Opus 5 | $0.00017 | $0.00871 |
| Sonnet 5 | $0.00007 | $0.00348 |
| Haiku 4.5 | $0.00003 | $0.00174 |
Grade A, and why
dspy-output-refinement-constraints scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 242 lines — stays where its author put it; the contents beside it link to each section on GitHub.
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
- Optimize programs: dspy-miprov2-optimizer
- Evaluate quality: dspy-evaluation-suite
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:
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 = pred.summary
word_count = len(summary.split())
if word_count > 100 or len(summary) < 50:
return 0.0
if "important" not in summary.lower():
return 0.5
return 1.0
# Refine module
refined_summarizer = dspy.Refine(
module=summarizer,
reward_fn=summary_reward,
N=3,
threshold=1.0
)
# Use it
result = refined_summarizer(document="Long document text here...")
print(result.summary)
Phase 2: dspy.BestOfN for Selection
Generate N outputs and pick the best:
What ships with it
1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 12d ago First seen · 242 lines · 35 tokens per session scan A 4550331692d3
dspy-output-refinement-constraints is a skill published in the GitHub repository OmidZamani/dspy-skills (123 stars, last pushed 2mo ago), licensed MIT. It adds 35 tokens to every session and 1,742 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
reasoning
AI reasoning authority — prompt engineering, chain-of-thought, self-consistency, evaluation frameworks, LLM judging, structured output, and prompt versioning patterns for production AI systems.
ai-engineering-toolkit
6 production-ready AI engineering workflows: prompt evaluation (8-dimension scoring), context budget planning, RAG pipeline design, agent security audit (65-point checklist), eval harness building, and product sense coaching.
prompt-optimization
Improve a prompt on the evaluations workbench through a measured loop. Score the baseline first, then duplicate the target column, form a hypothesis from failing rows, edit the copy's prompt draft, run, compare pass rate and cost, and repeat until the numbers hold. Use when the user asks to optimize or improve a…
prompts
Version and manage your agent's prompts with LangWatch Prompts CLI. Use for both onboarding (set up prompt versioning for an entire codebase) and targeted operations (version a specific prompt, create a new prompt version). Supports Python and TypeScript.
prompt-master
Generates optimized prompts for AI tools. Activates only when the user explicitly asks to write, fix, improve, or adapt a prompt for a specific AI tool (LLM, Cursor, Midjourney, image AI, video AI, coding agents, etc.). Does not activate for general conversation, coding tasks, document writing, or other…
llm-engineering-expert
Build reliable applications on large language models: prompt design, structured output, evaluation, guardrails, and cost and latency control. Use when the user mentions LLMs, prompts, prompt engineering, few-shot examples, structured or JSON output, function calling, hallucination, model evaluation, token costs…