Code Comprehension then Auditing for Unsupervised LLM Evaluation

Bhrij Patel, Souradip Chakraborty, Mengdi Wang, Dinesh Manocha, Amrit Singh BediarXiv 2024

TL;DR

Evaluating code correctness using LLMs without unit tests usually fails because models struggle to simultaneously understand raw code and judge its alignment with a task. This paper introduces CoCoA (Code Comprehension then Auditing), a framework that decouples this process by first generating a natural-language explanation of the code's behavior and then auditing that explanation against the task requirements. This simple shift from implementation space to explanation space yields up to a 68% increase in F1 score and makes the evaluation highly robust to misleading code comments.

What Problem Does This Paper Address?

How do you know if an LLM-generated code snippet is correct when you don't have reference solutions or unit tests? Unsupervised LLM-as-a-judge evaluation has become popular for its scalability, but existing methods typically feed the raw code implementation directly into the judge. This forces the LLM to jointly infer what the code does (comprehension) and whether it meets the specification (evaluation) in a single step.

This "entanglement" leads to systematic failures. LLM judges frequently misunderstand implicit logic or get tripped up by deceptive inline comments. This results in high false-negative rates—incorrectly flagging perfectly good code as buggy—which severely limits their utility in real-world workflows like automated code refinement.

Methods

The authors propose CoCoA (Code Comprehension then Auditing), a modular framework that splits the evaluation into two sequential steps:

  1. Code Comprehension (The Explainer): An LLM ($\pi_e$) takes the task description and the raw code, abstracting the low-level implementation details into a clear, natural-language explanation ($e$) of the program's actual behavior. The level of detail in this explanation is controlled by a hyperparameter $\lambda \in [1, 5]$.
  2. Auditing (The Judge): A second LLM call ($\pi_j$) evaluates task alignment based only on the generated natural-language explanation and the original task description, completely bypassing the raw code.
Figure 1: Code Comprehension then Auditing. Unsupervised LLM judges often directly evaluate code by reasoning over implementation details. We propose that first explaining the code to focus on functionality comprehension and auditing based on the explanation leads to more reliable and accurate evaluation.

Datasets

The framework was rigorously tested across 9 diverse datasets covering multiple programming languages (Python, C++, Go, Javascript, Java) and complexity levels:

  • HumanEval-X (HE): Multi-lingual variants (HE-PY, HE-CPP, HE-GO, HE-JS, HE-JAVA).
  • APPS & VibePass (VP): Competition and interview-level coding challenges featuring higher complexity.
  • BigCodeBench (BCB): Python benchmarks focusing on multiple function calls.
  • DebugBench (DB): A debugging benchmark containing specific error categories (Syntax, Logic, Reference, Multiple).

To test robustness, the authors generated adversarial versions of these datasets containing functionally incorrect code and code injected with misleading comments designed to trick the evaluator.

Key Insights and Ideas

  • Evaluating Explanations > Evaluating Code: Shifting the evaluation from the implementation space to the explanation space filters out low-level syntactic noise. It lets the judge focus entirely on behavioral alignment.
  • The Goldilocks Zone of Detail ($\lambda=2$): The authors experimented with five levels of explanation detail. Surprisingly, a moderate level of detail ($\lambda=2$, which describes the main algorithm and key assumptions without speculating on unhandled edge cases) performed best. Too much detail ($\lambda=5$) re-introduces implementation noise and triggers the model's over-cautious bias, leading to false negatives.
  • Immunity to Deceptive Comments: Because the explainer LLM must trace the actual execution logic to build its natural-language summary, CoCoA naturally filters out misleading inline comments that easily dupe standard LLM judges.
Figure 2: Representative Case: Better Code Comprehension Leads to Better Evaluation. In this example, baseline methods (red) incorrectly penalize the solution for misunderstanding the logic of the program. CoCoA (green) first explains the program to recover a natural- language description of its logic, and then evaluates whether this logic satisfies the task requirements. By judging the explanation rather than the raw code, CoCoA recognizes that the empty-list case is handled by the implementation.

Key Results

  • Massive F1 and Accuracy Gains: Across all datasets and backbones (GPT-4o-mini, Qwen-2.5-7B, Llama-3.1-8B), CoCoA consistently outperformed baselines like CodeJudge and Behavior Comparison. It achieved up to a 68% increase in F1 score and up to a 20% increase in accuracy.
  • Error Type Robustness: On DebugBench, CoCoA showed balanced improvements across all bug types (Syntax, Logic, Reference), proving it enhances semantic, behavior-level understanding.
  • Downstream Code Refinement: When used to provide feedback to a code-repair agent, CoCoA achieved a dramatically higher Preservation Rate (PR) (up to 27x higher than baselines), meaning it rarely broke already-correct code by falsely identifying bugs.

Limitations and Future Work

  • The False Positive Trade-off: While CoCoA drastically reduces false negatives (wrongly calling good code buggy), lower detail levels ($\lambda=2$) can slightly increase false positives by missing tiny bugs like a flipped inequality (< vs <=).
  • Future Directions: The authors suggest exploring how this explanation-based paradigm scales beyond isolated code snippets to complex, repository-level software maintenance tasks.

Summary updated

BibTeX
@misc{patel2024code,
  author = {Bhrij Patel and Souradip Chakraborty and Mengdi Wang and Dinesh Manocha and Amrit Singh Bedi},
  title = {{Code Comprehension then Auditing for Unsupervised LLM Evaluation}},
  year = {2024},
  eprint = {2410.03131},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.03131},
}
Figure