SemanticVul: Evidence-Grounded Structured LLM Explanations for Vulnerability Detection
SemanticVul is a reproducible framework for C/C++ vulnerability detection that leverages locally generated, evidence-grounded semantic explanations to significantly improve accuracy and minority-class recall over existing baselines, while rigorously validating claims through deterministic code matching and dataset auditing.
Original paper licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Software vulnerabilities are the hidden cracks in the digital world, the small mistakes in code that allow attackers to break into systems, steal data, or cause chaos. Because modern software is written in massive volumes, often in languages like C and C++ that are powerful but prone to these errors, human experts cannot possibly read every line to find the weak spots. To keep up, researchers have turned to artificial intelligence, specifically large language models, which are computer programs trained on vast amounts of text and code to understand patterns and meaning. These models can read a piece of software and explain what it is doing, offering a new way to spot dangerous flaws automatically. However, a significant problem has emerged: when these models are asked to explain code, they sometimes invent details that aren't there or accidentally reveal the answer before the analysis is even finished, making their help unreliable for critical security work.
A team of researchers at the National University of Sciences and Technology in Pakistan has developed a new system called SemanticVul to solve this problem. Instead of relying on expensive, commercial AI services that generate free-flowing, unverified text, their system uses a locally run, open-source model to produce structured, evidence-based explanations. The researchers built a pipeline where the AI must point to specific lines of code to back up every claim it makes about a security risk. If the AI cannot find the code it is talking about, the system discards that claim. They then tested this approach on two major collections of real-world software functions, known as Devign and Reveal, to see if this grounded, evidence-backed method could find more vulnerabilities than previous techniques.
The results show that this careful, evidence-first approach works significantly better than the standard methods currently in use. On the Reveal dataset, which contains a very small number of vulnerable functions mixed among many safe ones, the new system improved the ability to find those rare dangerous functions from about 40 percent to 63 percent. This is a crucial improvement because missing a vulnerability in a real-world system can be catastrophic. The system also managed to double the number of times it correctly linked its warnings to actual code snippets, while cutting the number of times it hallucinated or invented code references in half. By forcing the AI to stick to the facts present in the code and scrubbing out any language that might accidentally give away the answer, the researchers created a more trustworthy and effective tool for security analysis.
The researchers also explored how to best combine the raw code data with these new explanations. They tested three different ways of merging this information: using the code alone, mixing the code and explanation with a fixed method, and using a smart switch that decides for each piece of code how much weight to give the explanation. While the smart switch performed slightly better in some initial tests, the improvement was not consistent enough to be considered a definitive breakthrough. The most reliable finding was that the explanation channel itself—the part that provides the evidence-grounded reasoning—was the primary driver of the success. The system proved that when you strip away the guesswork and force the AI to anchor its reasoning in the actual text of the program, it becomes a far more powerful detector of security flaws.
Beyond just finding bugs, the study also uncovered issues with the data sets used to train and test these systems. The researchers found that some of the standard benchmarks contained duplicate code with conflicting labels, where the same function was marked as both safe and dangerous in different parts of the data. This kind of error can trick a computer into thinking it has learned something it hasn't actually learned. By auditing these data sets and cleaning out the contradictions, the team ensured that their results were based on genuine learning rather than memorizing errors. This attention to data quality, combined with the new method of generating explanations, suggests a path forward for building more reliable security tools that do not just guess, but actually understand the code they are protecting.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.