mlsanityData to 7 Oct 2026

Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision

arXiv 2603.01494 ↗First posted 2 Mar 2026cs.SE cs.AI cs.CRcited by 0

On the map: Retrieval-augmented generation → Privacy and security of RAG

Abstract (arXiv)

Large Language Models (LLMs) are increasingly deployed for code generation in high-stakes software development, yet their limited transparency in security reasoning and brittleness to evolving vulnerability patterns raise critical trustworthiness concerns. Models trained on static datasets cannot readily adapt to newly discovered vulnerabilities or changing security standards without retraining, leading to the repeated generation of unsafe code. We present a principled approach to trustworthy code generation by design that operates as an inference-time safety mechanism. Our approach employs retrieval-augmented generation to surface relevant security risks in generated code and retrieve related security discussions from a curated Stack Overflow knowledge base, which are then used to guide an LLM during code revision. This design emphasizes three aspects relevant to trustworthiness: (1) interpretability, through transparent safety interventions grounded in expert community explanations; (2) robustness, by allowing adaptation to evolving security practices without model retraining; and (3) safety alignment, through real-time intervention before unsafe code reaches deployment. Across real-world and benchmark datasets, our approach improves the security of LLM-generated code compared to prompting alone, while introducing no new vulnerabilities as measured by static analysis. These results suggest that principled, retrieval-augmented inference-time interventions can serve as a complementary mechanism for improving the safety of LLM-based code generation, and highlight the ongoing value of community knowledge in supporting trustworthy AI deployment.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in Privacy and security of RAG, one of 15 directions in Retrieval-augmented generation. Builds on 20 of its 29 references that are in the map. First posted on arXiv 2 Mar 2026.

Builds on

20 of 29 references.

References · 20

  1. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  2. 2021Program Synthesis with Large Language Modelscited by 3,509
  3. 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
  4. 2023LMSYS-Chat-1M: A Large-Scale Real-World LLM Conversation Datasetcited by 449
  5. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  6. 2022A Systematic Evaluation of Large Language Models of Codecited by 360
  7. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
  8. 2020Deep Learning based Vulnerability Detection: Are We There Yet?cited by 142
  9. 2019A Deep Look into Neural Ranking Models for Information Retrievalcited by 79
  10. 2023How Secure is Code Generated by ChatGPT?cited by 77
  11. 2024Vul-RAG: Enhancing LLM-based Vulnerability Detection via Knowledge-level RAGcited by 67
  12. 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 58
8 more
  1. 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 55
  2. 2023Is Stack Overflow Obsolete? An Empirical Study of the Characteristics of ChatGPT Answers to Stack Overflow Questionscited by 42
  3. 2023SALLM: Security Assessment of Generated Codecited by 35
  4. 2023FRANC: A Lightweight Framework for High-Quality Code Generationcited by 14
  5. 2023Enhancing Large Language Models for Secure Code Generation: A Dataset-driven Study on Vulnerability Mitigationcited by 14
  6. 2020A Large-scale Study of Security Vulnerability Support on Developer Q&A Websitescited by 12
  7. 2025Generative AI and LLMs in Industry: A text-mining Analysis and Critical Evaluation of Guidelines and Policy Statements Across Fourteen Industrial Sectorscited by 5
  8. 2017Secure Coding Practices in Java: Challenges and Vulnerabilitiescited by 4

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026Improving LLM-Assisted Secure Code Generation through Retrieval-Augmented-Generation and Multi-Tool Feedback
  2. 2025VulInstruct: Teaching LLMs Root-Cause Reasoning for Vulnerability Detection via Security Specifications
  3. 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices
  4. 2025SOSecure: Safer Code Generation with RAG and StackOverflow Discussions
  5. 2025SV-TrustEval-C: Evaluating Structure and Semantic Reasoning in Large Language Models for Source Code Vulnerability Analysis
  6. 2026Enhancing Reliability in LLM-Based Secure Code Generation
  7. 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
  8. 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection