← Lab /Software

LLM-generated CodeQL queries boost detection F1 by 82%

LLMs can synthesize CodeQL queries that significantly improve vulnerability detection performance

Software arXiv 9 Sep 2026 Method Prototype evidence

Published as “Towards Scalable and Cost-Efficient Vulnerability Detection: A Study on Automatic Query Generation”

Why it matters

Organizations can substantially improve static analysis coverage at low cost while keeping source code in-house, making large-scale vulnerability detection more accessible.

Summary

LLM-generated CodeQL queries detect 263% more true positives than the default CodeQL rule set without a significant rise in false-detection rate, and achieve an 82% higher average F1-score, with Kimi K2.5 delivering the best cost-performance (96 queries for <$13 detecting 50 CVEs). Evidence comes from a benchmark of 112 real-world Java CVEs drawn from NVD/MoreFixes, compared against the standard CodeQL queries and the PDBERT deep-learning baseline.

What they found 3

  1. LLM-generated queries increase true positive detections by 263% over default CodeQL queries without a significant FDR increase.

    “Specifically, our empirical results demonstrate that LLM-generated queries increased true positive detections by 263% compared to default CodeQL queries, notably without a significant increase in the False Detection Rate (FDR).”

  2. The approach improves average F1-score by 82% relative to the CodeQL baseline.

    “This represents an 82% improvement of average F1-Score over the CodeQL baseline, suggesting that our automated synthesis approach is a more practical alternative for real-world deployment.”

  3. Kimi K2.5 achieves the best cost-performance, generating 96 queries for < 13 USD and detecting 50 CVEs (263% increase over baseline).

    “Specifically, the model generated 96 CodeQL queries for less than 13 USD, successfully detecting 50 CVEs within the benchmark. This represents a 263% increase in the detection rate over the CodeQL baseline, rising from 19 to 50 detected vulnerabilities.”

Caveats 3

  • Gemini 3 Flash Preview, which previously exhibited superior proficiency in generating compilable queries, failed to correctly translate the underlying logic of vulnerability patterns into semantically meaningful CodeQL queries.
  • Claude Sonnet 4.5 achieved the highest vulnerability detection rate at 45.54%, this performance was offset by a higher FDR.
  • Kimi K2.5 demonstrated higher balance; it trailed Sonnet 4.5 by only a single CVE in terms of detection but maintained a FDR that was more than three percentage points lower.

What’s new here 4

  • Automatic synthesis of executable CodeQL queries from NVD vulnerability descriptions using LLMs.
  • A syntax-refiner agent that iteratively repairs non-compilable queries, boosting compilability.
  • Hybrid model strategy pairing a high-reasoning LLM (e.g., GPT 5.2 Codex) with a syntax-specialist (Gemini 3 Flash) to reduce cost.
  • Comprehensive cost-effectiveness analysis showing large detection gains at minimal monetary expense.