mlsanityData to 7 Oct 2026

DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation

arXiv 2604.09089 ↗First posted 10 Apr 2026cs.SE cs.AI cs.CRcited by 2

Not on the map. Why?

Abstract (arXiv)

Large Language Models (LLMs) for code generation can replicate insecure patterns from their training data. To mitigate this, a common strategy for security hardening is to fine-tune models using supervision derived from the final transformer layer. However, this design may suffer from a final-layer bottleneck: vulnerability-discriminative cues can be distributed across layers and become less detectable near the output representations optimized for next-token prediction. To diagnose this issue, we perform layer-wise linear probing. We observe that vulnerability-related signals are most detectable in a band of intermediate-to-upper layers yet attenuate toward the final layers. Motivated by this observation, we introduce DeepGuard, a framework that leverages distributed security-relevant cues by aggregating representations from multiple upper layers via an attention-based module. The aggregated signal powers a dedicated security analyzer within a multi-objective training objective that balances security enhancement and functional correctness, and further supports a lightweight inference-time steering strategy. Extensive experiments across five code LLMs demonstrate that DeepGuard improves the secure-and-correct generation rate by an average of 11.9% over strong baselines such as SVEN. It also preserves functional correctness while exhibiting generalization to held-out vulnerability types. Our code is public at https://github.com/unknownhl/DeepGuard.

Key facts. Cited by 2 papers in the map (data through 7 Oct 2026). Builds on 14 of its 25 references that are in the map. First posted on arXiv 10 Apr 2026.

Builds on

14 of 25 references.

References · 14

  1. 2020Scaling Laws for Neural Language Modelscited by 6,411
  2. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
  3. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  4. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
  5. 2023How Secure is Code Generated by ChatGPT?cited by 77
  6. 2024Instruction Tuning for Secure Code Generationcited by 63
  7. 2022What Do They Capture? -- A Structural Analysis of Pre-Trained Language Models for Source Codecited by 50
  8. 2024Constrained Decoding for Secure Code Generationcited by 35
  9. 2023Assessing the Security of GitHub Copilot Generated Code -- A Targeted Replication Studycited by 24
  10. 2024Can We Trust Large Language Models Generated Code? A Framework for In-Context Learning, Security Patterns, and Code Evaluations Across Diverse LLMscited by 17
  11. 2023A User-centered Security Evaluation of Copilotcited by 14
  12. 2024SecCoder: Towards Generalizable and Robust Secure Code Generationcited by 13
2 more
  1. 2025Guiding AI to Fix Its Own Flaws: An Empirical Study on LLM-Driven Secure Code Generationcited by 12
  2. 2022Unveiling Code Pre-Trained Models: Investigating Syntax and Semantics Capacitiescited by 9

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2026: 2.

2 papers.