Seedlabs
Source research

VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specifications

Hao Zhu, Jia Li, Cuiyun Gao, Jiaru Qian, Yihong Dong, Huanyu Liu et al. · 2026 · 23 citationsRead the paper

All 10 authors

L. F. Wang, Ziliang Wang, Xiaolong Hu, Ge Li

Large language models (LLMs) have achieved remarkable progress in code understanding and analysis tasks. However, state-of-the-art LLMs demonstrate limited performance in vulnerability detection tasks, and even state-of-the-art models struggle to distinguish vulnerable code from patched code. We argue that a key reason for this limitation is that LLMs lack an understanding of security specifications—the expectations defined by developers and security teams about how code should behave to remain safe. When the actual behavior of the code differs from these expectations and introduces a security risk, it becomes a potential vulnerability. However, such knowledge is rarely explicit in training data, leaving models unable to reason about the root causes of security flaws. To address this challenge, we propose VulInstruct, a specification-guided approach that systematically extracts reusable security specifications from historical vulnerabilities to instruct the detection of new ones. Specifically, VulInstruct designs two automatic pipelines to construct a specification knowledge base from complementary perspectives: (i) General specifications, extracted from high-quality patches across diverse projects, capturing fundamental safe behaviors accumulated across the open-source ecosystem; and (ii) Domain-specific specifications, context-dependent expectations repeatedly violated in particular repositories or domains that are relevant to the target code under analysis. Before analyzing new code, VulInstruct leverages this specification knowledge base to retrieve relevant past cases and their associated specifications, enabling LLMs to reason about expected safe behaviors rather than relying solely on surface patterns. We evaluate VulInstruct under strict evaluation criteria requiring both correct predictions and valid reasoning. On the PrimeVul dataset, VulInstruct achieves 45.0% F1-score (32.7% improvement) and 37.7% recall (50.8% improvement) compared to the strongest baselines, while uniquely detecting 24.3% of all identified vulnerabilities—2.4× more than any baseline. In pair-wise evaluation distinguishing vulnerable from patched code, VulInstruct also achieves a 32.3% relative improvement over the best baseline. Beyond benchmarks, VulInstruct discovered a previously unknown high-severity vulnerability in production code by recognizing violations of extracted specifications, demonstrating its practical value for real-world vulnerability discovery. All code and supplementary materials are available at https://github.com/zhuhaopku/VulInstruct.

What the full text shows

Working prototype
  • Achieved state-of-the-art vulnerability detection performance on the PrimeVul benchmark. — 45.0% F1-score (32.7% improvement over GPTLens) (PrimeVul dataset, using DeepSeek-V3)
  • Significant improvement in the ability to discover vulnerabilities (recall). — 37.7% recall (50.8% improvement over GPTLens) (PrimeVul dataset, using DeepSeek-V3)
  • Superior capability in distinguishing vulnerable functions from their patched versions. — 17.2% P-C accuracy and 7.4% VP-S score (32.3% improvement over best baseline) (PrimeVul pairwise evaluation)
  • High complementary detection capability compared to other systems. — 24.3% uniqueness score (Among 226 successfully detected CVEs across all systems)
  • Successfully identified a previously unknown high-severity logic vulnerability. — 1 CVE (CVE-2025-56538) (Real-world software auditing simulation)
Setup
Evaluated on PrimeVul (838 samples, 50% vulnerable/patched) using DeepSeek-V3 as the primary LLM, Qwen3-Embedding-0.6B for retrieval, and GPT-5 as the LLM-as-a-Judge for CORRECT evaluation metrics.
How
VulInstruct uses a dual-path retrieval system to provide LLMs with general security specifications (extracted from high-quality patches) and dynamically induced domain-specific specifications (derived from CVE cases). It employs a specification-guided reasoning framework to analyze code against these expected safe behaviors rather than surface patterns.
Limitations
Difficulty in verifying if framework-specific fixes truly eliminate flaws in highly domain-specific patches (e.g., LJPEG decoder logic). · Potential for false positives when the model identifies a vulnerability but fails to recognize the fix in the patched version.

Summarized by Gemma 4 from the open-access full text · 22 Nov 2026. Read it