PreprintCited by 3Natural Language Processing TechniquesTopic ModelingLogic, programming, and type systems

DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines

Open access
Singhvi, Arnav, Shetty, Manish, Tan, Shangyin, Potts, Christopher, Sen, Koushik, Zaharia, Matei, Khattab, Omar·2023·arXiv

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 implementation of LM Assertions is integrated into DSPy at https://github.com/stanfordnlp/dspy

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

DataCite · 10.48550/arxiv.2312.13382

Cites

15 of 16 references verified0 citation errors · 1 not checkable

Statistics

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Cites

Flagged first, then by citations

Research works printed but not linked: 4

  1. Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J. D., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., et al. Language models are few-shot learn- ers. Advances in neural information processing systems, 33:1877-1901, 2020.
  2. Khattab, O., Potts, C., and Zaharia, M. Baleen: Robust multi-hop reasoning at scale via condensed retrieval. Ad- vances in Neural Information Processing Systems, 34: 27670-27682, 2021.
  3. Khattab, O., Singhvi, A., Maheshwari, P., Zhang, Z., San- thanam, K., Vardhamanan, S., Haq, S., Sharma, A., Joshi, T. T., Moazam, H., Miller, H., Zaharia, M., and Potts, C. Dspy: Compiling declarative language model calls into self-improving pipelines. ICLR, 2024.
  4. Yao, S., Yu, D., Zhao, J., Shafran, I., Griffiths, T. L., Cao, Y., and Narasimhan, K. Tree of thoughts: Deliber- ate problem solving with large language models. arXiv preprint arXiv:2305.10601, 2023. DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines TweetGen w/ Primitive Instructions (Dev/Test) Strategy No "#" Has Answer Concise Engaging Faithful Quality Vanilla 3.3 / 3.0 53.7 / 48.2 96.3 / 97.0 35.7 / 36.4 80.0 / 81.2 33.7 / 30.4 Infer w/ Assert 49.3 / 49.6 50.3 / 41.8 92.0 / 92.4 45.3 / 41.0 72.3 / 74.0 34.3 / 27.8 Compile 0.0 / 0.2 55.7 / 46.2 100 / 99.6 47.3 / 46.6 78.3 / 76.8 36.7 / 30.8 Compile w/ Assert 98.7 / 97.4 55.0 / 45.8 99.3 / 99.0 1.3 / 2.6 65.3 / 70.0 40.4 / 34.3 C+Infer w/ Assert 41.3 / 41.0 55.7 / 48.2 94.7 / 93.8 54.3 / 60.2 76.7 / 81.2 40.3 / 35.0 · arXiv

Cited by

Sorted by citations

Authors
Singhvi, A., Shetty, M., Tan, S., Potts, C., Sen, K., Zaharia, M., & Khattab, O.
Venue
arXiv
Publisher
arXiv
Published
2023
ISSN
2331-8422 (ISSN-L)
OpenAlex
W4390136380
Cited by
2
References
16
Citations by year
2025: 2
Type
posted content
Language
en
Open access
Locations
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Topics
  • Physical Sciences › Computer Science › Artificial Intelligence › Natural Language Processing Techniques
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
  • Physical Sciences › Computer Science › Artificial Intelligence › Logic, programming, and type systems
Keywords
DSPy, computational resource constraints, self-refinement, prompt engineering, program compilation, text generation, constraint compliance

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review