SPADE: Synthesizing Assertions for Large Language Model Pipelines

Shreya Shankar, Haotian Li, Parth Asawa, Madelon Hulsebos, Yiming Lin, J. D. Zamfirescu-Pereira, Harrison Chase, Will Fu-Hinthorn, Aditya G. Parameswaran, Eugene Wu · DOI

Introduction

Deploying Large Language Models (LLMs) in production environments presents a significant challenge: unpredictability. Despite rigorous prompt engineering, LLMs frequently hallucinate, fail to adhere to formatting constraints, or produce outputs with inappropriate tone. To mitigate these risks, developers often rely on data quality assertions—automated, post-hoc checks that validate model outputs. However, manually authoring these assertions is a labor-intensive process that requires developers to anticipate every possible failure mode and write complex validation code or secondary "judge" prompts.

This paper introduces SPADE (System for Prompt Analysis and Delta-Based Evaluation), a framework designed to automate the generation of robust LLM guardrails by leveraging the implicit requirements embedded in a developer's prompt history.

Methodology

SPADE operates on the insight that the iterative process of prompt engineering—where developers refine instructions to correct observed errors—is effectively a form of incremental specification. The system captures these specifications through a multi-stage pipeline.

The SPADE workflow: from prompt edits to deployed assertions.

1. Assertion Synthesis via Prompt Deltas

SPADE analyzes the "deltas" (differences) between consecutive versions of a prompt. By identifying what was added or removed, the system reconstructs the developer's intent. To categorize these changes, SPADE utilizes a custom taxonomy that distinguishes between structural requirements and content-based instructions.

Taxonomy of prompt deltas used by SPADE to categorize developer intent.

As shown in the taxonomy, prompt changes are broadly classified into Structural (e.g., response format, example demonstrations) and Content-Based (e.g., workflow descriptions, inclusion/exclusion instructions). SPADE then uses an LLM to synthesize Python functions that programmatically check for these specific requirements.

2. Filtering and Optimization

Generating assertions for every prompt edit can lead to a "wall of noise" characterized by redundant or overly sensitive checks. To address this, SPADE employs Integer Linear Programming (ILP) to select an optimal subset of assertions. The objective is to maximize "coverage" (the ability to catch known bad outputs) while remaining below a user-defined threshold for "false failures" (incorrectly flagging valid outputs).

3. Assertion Subsumption

In environments with limited labeled data, SPADE utilizes assertion subsumption. This logic identifies when one assertion is a prerequisite for another (e.g., a check for valid JSON is subsumed by a check for a specific JSON schema). By recognizing these logical hierarchies, SPADE can maintain high safety coverage even when specific failure examples have not yet been observed.

Evaluation and Results

The researchers evaluated SPADE using 19 real-world LLM pipelines to build the delta taxonomy and 9 diverse evaluation pipelines spanning tasks such as GitHub PR reviews, SaaS onboarding, and financial summarization. The evaluation utilized a mix of synthetic and human-labeled datasets, averaging 75 examples per pipeline.

Key findings include:

  • Efficiency: SPADE reduced the total number of deployed assertions by 14% compared to baseline methods.
  • Accuracy: The system decreased false failures by 21%, significantly reducing the manual burden of reviewing false positives.
  • Redundancy Identification: The taxonomy revealed that 65% of prompt changes are content-based, which frequently lead to overlapping instructions that SPADE successfully prunes.

Real-World Impact and Conclusion

SPADE demonstrates that prompt history is a rich, untapped source of truth for system evaluation. Beyond theoretical performance, SPADE has been integrated into LangSmith (LangChain’s production platform), where it has already been used to generate assertions for over 2,000 pipelines across various industries.

While the system currently excels at single-prompt pipelines, future work will explore multi-step chains and agents. Additionally, improving the synthesis of code for generic "exclusion" instructions (e.g., "avoid unrelated ideas") remains a priority to further reduce the occurrence of vague or overly strict assertions.

Summary updated

BibTeX
@article{shankar2024spade,
  author = {Shreya Shankar and Haotian Li and Parth Asawa and Madelon Hulsebos and Yiming Lin and J. D. Zamfirescu-Pereira and Harrison Chase and Will Fu-Hinthorn and Aditya G. Parameswaran and Eugene Wu},
  title = {{SPADE: Synthesizing Assertions for Large Language Model Pipelines}},
  journal = {Proc. VLDB Endow.},
  year = {2024},
  doi = {10.14778/3685800.3685835},
}
Figure