DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines
Arnav Singhvi, Manish Shetty, Shangyin Tan, Christopher Potts, Koushik, Sen, Matei Zaharia, Omar Khattab

TL;DR
This paper introduces LM Assertions within the DSPy framework to enforce computational constraints on language models, improving reliability, compliance, and task performance through self-refinement strategies.
Contribution
It presents a novel programming construct called LM Assertions for expressing constraints and integrates it into DSPy, enabling more reliable and accurate language model pipelines.
Findings
LM Assertions increase constraint compliance by up to 164%.
Task performance improves with up to 37% higher quality responses.
Strategies for automatic self-refinement enhance system reliability.
Abstract
Chaining language model (LM) calls as composable modules is fueling a new way of programming, but ensuring LMs adhere to important constraints requires heuristic "prompt engineering". We introduce LM Assertions, a programming construct for expressing computational constraints that LMs should satisfy. We integrate our constructs into the recent DSPy programming model for LMs, and present new strategies that allow DSPy to compile programs with LM Assertions into more reliable and accurate systems. We also propose strategies to use assertions at inference time for automatic self-refinement with LMs. We report on four diverse case studies for text generation and find that LM Assertions improve not only compliance with imposed rules but also downstream task performance, passing constraints up to 164% more often and generating up to 37% more higher-quality responses. Our reference…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsTopic Modeling · Software Engineering Research · Natural Language Processing Techniques
