dspy-assertions

Installation
SKILL.md

Enforce Constraints with dspy.Assert and dspy.Suggest

REMOVED IN DSPy 3.x. dspy.Assert and dspy.Suggest have been removed from the DSPy codebase (no assertions.py, no imports in __init__.py, retry.py commented out, no docs page). Use dspy.Refine or dspy.BestOfN instead — see /dspy-refine and /dspy-best-of-n. This skill documents the legacy API for maintaining existing codebases only.

Migration guide:

Old pattern New equivalent
dspy.Assert(condition, msg) (hard rule, retry) dspy.Refine(module, N=3, reward_fn=..., threshold=0.8)
dspy.Suggest(condition, msg) (soft rule, continue) Lower weight in reward function (penalize but don't block)
max_backtrack_attempts=2 N=3 in Refine/BestOfN
DSPyAssertionError on exhaustion fail_count parameter in Refine/BestOfN
Error message as feedback Refine auto-generates feedback from reward scores

Guide the user through adding runtime constraints to DSPy programs. Assertions let you declare what valid output looks like — DSPy handles retrying, backtracking, and feeding error messages back to the LM automatically.

Two kinds of constraints

dspy.Assert dspy.Suggest
Related skills

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

Installs
2
GitHub Stars
5
First Seen
6 days ago