A multi-agent pipeline mines secure coding practices from GitHub to fine-tune or augment LLMs, targeting weakness classes with few known examples. On a new benchmark it lifts Func-Sec@1 by up to 6.2 percentage points over the best prior method.
| Methods | CodeLlama-7B | DeepSeek-Coder-7B | Qwen-Coder-7B | |||
|---|---|---|---|---|---|---|
| Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | |
| Pre-trained | 17.8% | 9.3% | 20.3% | 14.2% | 25.8% | 20.3% |
| Li et al. (Li et al., 2024a) | 11.9% | 5.4% | 22.4% | 15.9% | 26.2% | 21.0% |
| SafeCoder (He et al., 2024) | 18.8% | 10.7% | 18.1% | 11.5% | 24.2% | 17.4% |
| Secure-Instruct (Li et al., 2026) | 27.4% | 15.3% | 25.7% | 17.7% | 29.1% | 19.3% |
| Secure-Miner (w/o Refinement Agent) | 20.1% | 12.8% | 19.0% | 12.2% | 22.8% | 15.3% |
| Secure-Miner (Full) | 27.7% | 17.8% | 29.5% | 20.1% | 33.3% | 25.5% |
| Methods | Claude-Sonnet-4.5 | GPT-5.4-mini | DeepSeek-V4-PRO | |||
|---|---|---|---|---|---|---|
| Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | |
| Pre-trained | 39.1% | 36.6% | 45.4% | 41.6% | 44.3% | 39.5% |
| CodeGuarder | 57.2% | 44.7% | 61.8% | 51.2% | 57.4% | 46.9% |
| CodeGuarder + Secure-Miner | 59.1% | 48.8% | 64.5% | 53.6% | 59.1% | 49.7% |
Going deeper
Imagine a cooking school that only teaches recipes by showing what went wrong: burnt dishes, raw centres, spoiled ingredients, and how to rescue each one. Students learn to fix mistakes but never see a dish cooked right the first time. That is roughly how most secure-code training works today—models study bugs and their patches, so they mainly know security as damage repair.
This paper sends scouts to thousands of popular kitchens and asks: show me a dish that was cooked safely from scratch. Three inspectors work in sequence: one writes a checklist of what safe cooking looks like for each hazard, one tastes the dish to confirm it really is safe, and one strips away the restaurant's branding and garnish so the student sees only the core technique.
The result is a recipe book of 1,411 safe techniques covering hazards that almost never appear in the mistake-and-fix reports. When student chefs study it, they pass safety and taste tests more often than students trained on any prior curriculum—but the exam only covers those rare hazards, and the inspectors themselves are AI, not human experts.
The abstract, word for word, with the seven densest phrases unpacked.
Most existing research on secure code generation for Large Language Models (LLMs) heavily relies on disclosed vulnerability reports or synthetic datasets for fine-tuning1. This approach frequently overlooks the diverse, secure coding practices that emerge naturally during real-world software development. This paper bridges this gap by proposing a novel framework to automatically extract and leverage secure practices observed in the wild to enhance secure code generation, with a particular focus on low-resource Common Weakness Enumerations (CWEs)2. Our methodology utilizes a multi-agent system consisting of: (1) a RegEx Agent that dynamically formulates security-related patterns based on CWE descriptions, optimized through an iterative feedback loop3; (2) a Verification Agent that precisely identifies genuine secure functions from open-source repositories4; and (3) a Refinement Agent that isolates core secure patterns by simplifying external dependencies5 to compile a high-quality dataset. To evaluate our approach, we construct a novel benchmark, CWEvallow, consisting of 74 executable scenarios covering 56 unique low-resource CWE-language pairs6. We conduct extensive experiments across both medium-sized open-source LLMs and state-of-the-art commercial LLMs. For medium-sized models (CodeLlama, DeepSeek-Coder, and Qwen-Coder), fine-tuning on our mined dataset consistently outperforms existing state-of-the-art baselines, achieving an absolute improvement of up to 6.2% on the Func-Sec@1 metric without sacrificing functional correctness7. Furthermore, when integrated into Retrieval-Augmented Generation (RAG) frameworks for commercial models (Claude-Sonnet-4.5, GPT-5.4-mini, and DeepSeek-V4-PRO), our dataset successfully complements existing security-hardening baselines, yielding the highest overall security and functionality performance. Our findings demonstrate the robustness, generalizability, and effectiveness of leveraging real-world secure practices to mitigate low-resource software vulnerabilities.
Two lines of work converge: mining security data from repositories, and hardening LLM code generation.
Read five parts, in this order.
Skip Section 2 if you already know BigVul, CVEfixes, and prior LLM security hardening work.
If the gains are smaller or less general than they look, these are the places to check.
| Methods | CodeLlama-7B | DeepSeek-Coder-7B | Qwen-Coder-7B | |||
|---|---|---|---|---|---|---|
| Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | Sec@1 | Func-Sec@1 | |
| Pre-trained | 17.8% | 9.3% | 20.3% | 14.2% | 25.8% | 20.3% |
| Li et al. (Li et al., 2024a) | 11.9% | 5.4% | 22.4% | 15.9% | 26.2% | 21.0% |
| SafeCoder (He et al., 2024) | 18.8% | 10.7% | 18.1% | 11.5% | 24.2% | 17.4% |
| Secure-Instruct (Li et al., 2026) | 27.4% | 15.3% | 25.7% | 17.7% | 29.1% | 19.3% |
| Secure-Miner (w/o Refinement Agent) | 20.1% | 12.8% | 19.0% | 12.2% | 22.8% | 15.3% |
| Secure-Miner (Full) | 27.7% | 17.8% | 29.5% | 20.1% | 33.3% | 25.5% |
LLM-Only Verification. The Verification Agent relies solely on an LLM to assess whether extracted code securely mitigates a target CWE, without complementary static analysis tools. This design choice is intentional, because many low-resource CWEs are unsupported by existing static analysis tools, making automated tool-based verification infeasible for our target vulnerability classes. Nonetheless, LLM-based verification may miss subtle security flaws that a specialized tool might detect.
Benchmark Construction Limitation. CWEvallow draws 64 of its 74 scenarios from CWEval and the remaining 10 from manually extended CyberSecEval scenarios. The limited number of CyberSecEval scenarios is due to the inherent difficulty of constructing executable test cases from real-world repository contexts, i.e., many scenarios lack the self-contained structure needed to support both security and functionality testing, making only a small subset suitable for dynamic evaluation.
Nothing on this page was recomputed. Every claim points to the paper so you can check it.
More latest news
Read all