Skip to main content
QUICK REVIEW

[論文レビュー] Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision

Manisha Mukherjee, Vincent J. Hellendoorn|arXiv (Cornell University)|Mar 2, 2026
Software Engineering Research被引用数 0
ひとこと要約

SOSecure はコード生成後に Stack Overflow のセキュリティ議論を検索して LLM の改訂を誘導し、再訓練なしで潜在的に安全でないコードを修正し、セキュリティを向上させる。

ABSTRACT

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.

研究の動機と目的

  • 推論時の安全性を可能にして再訓練なしで信頼性のあるコード生成を促進する。
  • Stack Overflow からコミュニティの知識を活用し、コードパターンに関連するセキュリティ上の懸念を顕在化させる。
  • 生成後の検索がセキュリティ成果を改善するかを、新たな脆弱性を生み出さない範囲で評価する。
  • 検索ベースの改訂メカニズムを通じて解釈性、頑健性、安全性の整合性を示す。

提案手法

  • 明示的なセキュリティ議論をフィルタリングしたセキュリティ重視の Stack Overflow 知識ベースを構築する。
  • BM25 を用いて生成コードとの語彊類似度に基づき上位 k=5 件の関連セキュリティ議論を取得する。
  • 取得した議論を改訂プロンプトの助言的文脈として提供し、コードの注入や変更の強制は行わない。
  • LLM に対してコードをどう改訂するかを判断させ、変更なしを有効な選択肢として認める。
  • 複数のデータセットを横断して静的解析ツール(CodeQL と Bandit)を用い、修正率と新規脆弱性の導入を測定する。
  • 検索ベースの改訂がモデル依存でなく、再訓練を必要としないことを示す。
Figure 1: AnswerID: 61307412, which includes community comments providing security insights. This content was used as context to enhance the generated code in SOSecure.
Figure 1: AnswerID: 61307412, which includes community comments providing security insights. This content was used as context to enhance the generated code in SOSecure.

実験結果

リサーチクエスチョン

  • RQ1Stack Overflow 論議を用いた検索強化改訂は、 prompting のみよりも LLM 生成コードのセキュリティを向上させるか?
  • RQ2コミュニティの説明からの推論時ガイダンスは、複数データセットと言語にまたがって新たな脆弱性を導入せずに脆弱性を減らせるか?
  • RQ3再訓練を行わずに、セキュリティ実践の変化に対して手法は頑健か?

主な発見

Dataset | Prompt-only | GPT-4+CWE | SOSecure | Δ Fix Rate | Intro Rate (SOSecure)SALLMLLMSecEvalLMSys
SALLM49.1%58.5%71.7%+22.6%0.0%
LLMSecEval56.5%69.6%91.3%+34.8%0.0%
LMSys37.5%45.8%96.7%+59.2%0.0%
  • SOSecure はすべてのデータセットで prompts のみの場合より修正率を大きく向上させる(例:SALLM: +22.6 ポイント、LMSys: +59.2 ポイント)。
  • SOSecure は脆弱性ラベルのベースライン GPT-4+CWE を上回ることが多く、説明の追加はラベル以上の価値をもたらす。
  • データセットを横断して、SOSecure は静的解析で新たな脆弱性を導入しない。
  • アブレーション実験により、コミュニティ議論の取得が大きなセキュリティ向上をもたらし、自己改訂のみが要因ではないことを示す。
  • C 言語コードで、SOSecure の修正率は 73.3%(Promptのみ 53.3%、GPT-4+CWE 60.0%)であり、新たな脆弱性はなし。
  • この手法は多言語で機能し、再訓練なしで進化するセキュリティ実践への頑健性を示唆する。
Figure 2: Inference-time revision guided by community knowledge. Left: original GPT-4 output containing a usage pattern commonly associated with CWE-078. Right: one possible revised output produced after the model is provided with a relevant Stack Overflow discussion (Figure 1 ) as contextual guidan
Figure 2: Inference-time revision guided by community knowledge. Left: original GPT-4 output containing a usage pattern commonly associated with CWE-078. Right: one possible revised output produced after the model is provided with a relevant Stack Overflow discussion (Figure 1 ) as contextual guidan

より良い研究を、今すぐ始めましょう

論文設計から論文執筆まで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。