dspy-assertions
Installation
SKILL.md
Enforce Constraints with dspy.Assert and dspy.Suggest
REMOVED IN DSPy 3.x.
dspy.Assertanddspy.Suggesthave been removed from the DSPy codebase (noassertions.py, no imports in__init__.py,retry.pycommented out, no docs page). Usedspy.Refineordspy.BestOfNinstead — see/dspy-refineand/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=2N=3in Refine/BestOfNDSPyAssertionErroron exhaustionfail_countparameter in Refine/BestOfNError 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.