CAT-RAG: Improving Secure Code Generation with Category-Aware Agentic Retrieval
Mahdieh Abazar, Lorenzo De Carli, Benjamin Tan
Key points
From the paper's conclusion- We propose CAT-RAG, an agentic security category-aware retrieval-augmented code generation framework.
Abstract
Despite rapid progress in LLM-based code generation, security vulnerabilities remain widespread, and retrieval-augmented code generation (RACG) can further amplify risk when retrieved knowledge is verbose or vulnerable to poisoning. Existing secure RACG approaches inject security knowledge at a fine-grained vulnerability level, causing prompt overhead and diluted model attention when a query implicates multiple related weaknesses. We propose CAT-RAG, an agentic security category-aware retrieval-augmented code generation framework. CAT-RAG performs adaptive category selection via an LLM as a categorizer agent and operates either as a standalone security layer or as a drop-in add-on to RACG pipelines, requiring no modification to the underlying model. We replace CWE-level retrieval with compact, language-specific security categories. These categories provide a higher-level abstraction over individual CWE weaknesses, organizing them by the security concern they share, such as Input Validation and Injection Attacks, rather than merely grouping related entries. Each category consolidates best practices and secure code examples into a single, prompt-efficient representation. We perform a comprehensive evaluation across CyberSecEval, CodeGuard+, and HumanEval. On CyberSecEval, CAT-RAG nearly doubles the secure code generation improvement over the state of the art (23.57% vs. 12.11%) while reducing token overhead by 41.71%.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code GenerationarXiv · 2026
- A.S.E 2.0: Understanding How Repository Context Impacts the Security of LLM-Generated CodearXiv · 2026
- Toward Secure Code Generation: Bridging Correctness and Security via Task-Adaptive Vulnerability Modeling and Execution-Based BenchmarkingProceedings of the ACM on software engineering. · 2026
- CQLLM: A Framework for Generating CodeQL Security Vulnerability Detection Code Based on Large Language ModelApplied Sciences · 2026
- Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGACM Transactions on Software Engineering and Methodology · 2026
- Secure and Functional Code Generation with Self-EvaluationarXiv · 2026