DeCon: Detecting Incorrect Assertions via Postconditions Generated by a Large Language Model

Hao Yu, Tianyu Chen, Jiaming Huang, Zongyang Li, Dezhi Ran, Xinyu Wang, Ying Li, Assaf Marron, David Harel, Yuan Xie, Tao XiearXiv 2025 · DOI

Abstract

While Large Language Models (LLMs) have shown remarkable capabilities in code generation, their ability to self-test remains a significant bottleneck. Research indicates that over 60% of LLM-generated assertions are incorrect, leading to a high rate of false positives that burden developers. This paper presents DeCon (Detecting incorrect assertions via Conditions), a framework that utilizes LLMs to generate symbolic postconditions to automatically identify and discard faulty test cases. By validating these postconditions against existing docstring examples, DeCon creates a reliable "partial oracle" for assertion filtering. Experimental results on the HumanEval benchmark demonstrate that DeCon detects an average of 64% of incorrect assertions, leading to measurable improvements in code generation quality and reliability.

Introduction: The Oracle Problem in AI Coding

The integration of Large Language Models (LLMs) into software development workflows has accelerated code production, but ensuring the correctness of this code remains a challenge. A common approach is to have the LLM generate unit tests alongside the code. However, these models often "hallucinate" expected outputs, resulting in incorrect assertions. In the standard HumanEval benchmark, approximately 62% of LLM-generated assertions are faulty. This "oracle problem"—the difficulty of determining if a test result is correct—undermines the utility of automated testing and increases the debugging burden on developers.

Overview of the DeCon framework illustrating the detection of incorrect assertions through postcondition filtering using a HumanEval example.

Methodology: The DeCon Pipeline

DeCon addresses the oracle problem through a multi-stage pipeline designed to synthesize and verify logical postconditions. The framework essentially uses the logic of the problem to verify the specifics of the test case.

  1. Assertion Generation: A pool of candidate assertions is generated for a target function using standard LLM prompting.
  2. Postcondition Generation: Simultaneously, an LLM (e.g., GPT-4) generates symbolic postconditions—logical predicates that must hold true after the function executes (e.g., "the returned list should only contain unique elements").
  3. Postcondition Filtering: To prevent the use of hallucinated postconditions, DeCon validates them against user-provided I/O examples typically found in function docstrings. Postconditions that contradict these ground-truth examples are discarded.
  4. Incorrect Assertion Detection: The remaining vetted postconditions serve as a filter. Any generated assertion that violates a postcondition is flagged as incorrect and removed from the test suite.
The DeCon system architecture, showing the parallel paths for assertion and postcondition generation and their subsequent filtering.

Evaluation and Datasets

The researchers evaluated DeCon using three primary datasets:

  • HumanEval: The standard benchmark consisting of 164 Python programming problems.
  • HumanEvalFix: A version of the benchmark with manually injected bugs used to test fault-finding capabilities.
  • DeCon-AssertData: A newly generated dataset containing tens of thousands of assertions produced by four major models: CodeGen, InCoder, Codex, and GPT-3.5.

Key Results

  • High Detection Accuracy: DeCon successfully identified an average of 64% of incorrect assertions across various models. When using GPT-4 for postcondition generation, it achieved 65.5% precision and over 93% recall.
  • Improved Code Quality: By filtering out noisy test cases, the "Pass@1" metric for code generation improved by 4%, as the model could more accurately select correct code versions based on valid tests.
  • Signal Preservation: The filtering process is highly surgical; it retained 99.3% of the assertions' original ability to detect real bugs, effectively removing noise without losing the signal.

Conclusion

DeCon demonstrates that the logical reasoning capabilities of LLMs can be harnessed to verify their own specific outputs. By shifting the focus from specific I/O pairs to general symbolic postconditions, DeCon provides a robust mechanism for cleaning up automated test suites. Future work will explore extending this framework to more complex data types and non-deterministic functions, further bridging the gap toward fully reliable AI-driven software engineering.

Summary updated

BibTeX
@misc{yu2025decon,
  author = {Hao Yu and Tianyu Chen and Jiaming Huang and Zongyang Li and Dezhi Ran and Xinyu Wang and Ying Li and Assaf Marron and David Harel and Yuan Xie and Tao Xie},
  title = {{DeCon: Detecting Incorrect Assertions via Postconditions Generated by a Large Language Model}},
  year = {2025},
  eprint = {2501.02901},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.02901},
}
Figure