[2604.09089] DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation
About this article
Abstract page for arXiv paper 2604.09089: DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation
Computer Science > Software Engineering arXiv:2604.09089 (cs) [Submitted on 10 Apr 2026] Title:DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation Authors:Li Huang, Zhongxin Liu, Yifan Wu, Tao Yin, Dong Li, Jichao Bi, Nankun Mu, Hongyu Zhang, Meng Yan View a PDF of the paper titled DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation, by Li Huang and 8 other authors View PDF HTML (experimental) Abstract: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 correctnes...