Recall and Consistency of LLMs in Cybersecurity Vulnerability Detection: Engineering Insights from Large-Scale Testing
Large language models are increasingly used for code vulnerability detection, but real-world deployment requires balancing recall, inference consistency, and cost. Based on a security team's benchmark of over ten billion tokens across massive codebases, this article explains how multi-run pooling can maximize recall, why unstable single-run outputs undermine automated security pipelines, and how a tiered model strategy can deliver near-frontier performance at roughly 70% lower inference cost. It also offers practical recommendations for model selection, evaluation metrics, feedback loops, and cost governance.
As large language models (LLMs) become embedded in software engineering, LLM-based code vulnerability detection and security analysis has grown into a critical part of enterprise security. A recent security team benchmark tested models against massive codebases consuming more than ten billion tokens. The results not only reveal the recall limits of current mainstream models but also expose serious engineering challenges around inference consistency and cost-effectiveness in real-world deployments. This article strips away product-specific details and analyzes the technical logic and engineering lessons behind the test data.
1. Recall and Pooling Effects: Ensemble Thinking in Security Detection
Recall is the core metric for a model’s ability to uncover potential vulnerabilities. The test data shows that some models, after aggregating multiple inference runs, achieve extremely high recall. For example, one high-performance model reached the best result on the benchmark (28/32) by taking the union of findings across three independent inferences, clearly ahead of other frontier models, which generally scored between 25/32 and 26/32.
This “pooling boosts recall” phenomenon is essentially an application of ensemble learning. Because generation is influenced by temperature and sampling mechanisms, a single LLM inference is somewhat random. Running multiple analyses of the same code segment and merging the vulnerability sets can effectively reduce missed detections caused by any single inference path.
In security contexts, missed vulnerabilities can lead to serious incidents, so high pooled recall has substantial business value. But is this simple “stacking” of inference runs a universally viable engineering approach? That question leads to the next issue: inference consistency.
2. The Inference Consistency Challenge: Single-Run Performance vs. Stable Hit Rate
Although the model above topped the pooled recall rankings, the test details revealed a significant inconsistency problem. In its first inference it found only 17 vulnerabilities, and only 10 vulnerabilities were consistently detected across all three runs. In other words, high pooled recall was “assembled” from runs with low individual reliability, with many findings flickering in and out between runs.
In automated security pipelines, such unstable behavior creates serious engineering burdens:
- Difficult reproduction and tracking: If the same code produces a different vulnerability list on every scan, security engineers cannot establish a stable baseline for tracking remediation.
- Alert fatigue and loss of trust: Unstable outputs erode developers’ trust in the automation, eventually causing the tool to be sidelined.
To evaluate this dimension quantitatively, here is a Python pseudocode framework for multi-dimensional model evaluation:
def evaluate_security_detection(model_results, ground_truth):"""model_results: a list of detection sets from multiple runs, e.g. [set1, set2, set3]ground_truth: the set of real vulnerabilities"""# 1. Single-run recall (using the first inference as an example)single_recall = len(model_results[0] & ground_truth) / len(ground_truth)# 2. Pooled recall (union of results from multiple runs)pooled_detected = set.union(*model_results)pooled_recall = len(pooled_detected & ground_truth) / len(ground_truth)# 3. Consistent hit rate (intersection of results from multiple runs)consistent_hits = set.intersection(*model_results)consistency_rate = len(consistent_hits & ground_truth) / len(ground_truth)return {"single_recall": single_recall,"pooled_recall": pooled_recall,"consistency_rate": consistency_rate}
To address consistency, developers should not simply increase the number of inference runs. More sensible technical approaches include applying a Self-Consistency voting mechanism, optimizing system prompts to focus the model on specific vulnerability patterns, and lowering the temperature to limit output divergence.
3. Cost-Effectiveness Trade-offs: Balancing Performance and Expense
Beyond accuracy and consistency, deploying LLMs for security requires accounting for compute cost. At the scale of ten-plus billion tokens, inference cost directly determines whether security scanning can run routinely.
The benchmark showed that another model achieved 25/32 recall—only one vulnerability fewer than the frontier result—while cutting inference cost by nearly 70%. This “near-frontier” performance combined with a dramatically better cost structure offers enterprises a new perspective on security model selection.
In cloud-native architectures, large-scale code security scanning relies on elastic compute resources and container platforms for distributed scheduling. Chasing maximum recall with the highest-spec models creates unsustainable financial pressure, while over-cutting costs risks missing critical vulnerabilities. A tiered, hybrid-model strategy has therefore become a common best practice:
- Broad coverage stage: Use low-cost, near-frontier models for frequent scans of the entire codebase, covering most common vulnerabilities (such as injection risks and unauthorized access) at minimal expense.
- Targeted review stage: For high-risk code segments flagged in the first stage, invoke stronger models with larger context windows and multiple pooled inferences for verification, ensuring the security of critical assets.
4. Engineering Recommendations for Security LLM Selection and Deployment
Based on the analysis above, when introducing LLMs into vulnerability detection pipelines, development and security teams should establish a scientific evaluation system and architecture:
- Multi-dimensional evaluation metrics: Do not rely solely on vendor-advertised peak recall. Include “single-run recall” and “stable hit rate” as model acceptance criteria. Only models with stable, high single-run recall can genuinely integrate into CI/CD pipelines.
- Closed-loop optimization: Connect model outputs to internal log services and monitoring/alerting systems. For cases the model flags as vulnerabilities but human review determines to be false positives, build feedback datasets and continuously improve performance through fine-tuning or in-context learning.
- Dynamic cost control: Use enterprise cloud monitoring capabilities to meter token consumption in real time and enforce quotas on security scanning tasks. Set budget alerts to prevent overspend caused by codebase growth or scanning logic defects.
Conclusion
LLMs show enormous potential in cybersecurity vulnerability detection. The ten-billion-token benchmark confirmed their ability to discover complex vulnerabilities, but also exposed engineering pain points: inconsistent inference and high cost. The future of AI in security will not be a single-model compute arms race; it will move toward multi-model collaboration, fine-grained cost management, and optimized output stability. Teams must find the right balance of recall, consistency, and cost for their own circumstances.
