Metraipolis › archive › dc_d05d4a7deb9c

Interpreting and Steering for Safe and Correct Code Generation — arXiv:2608.30025

Source
arXiv (en)
Original
https://arxiv.org/abs/2608.30025
License (as archived)
CC0-1.0
Archived
2026-10-17T07:44:28.506Z
SHA-256 of the archived text
ff70a310e14c67f6e23625e8a99c74a70f6a5d7d570d7b2a4b13301be2bdbdbc
Stable URL of this page
https://metraipolis.com/documento/dc_d05d4a7deb9c

How to cite

Interpreting and Steering for Safe and Correct Code Generation — arXiv:2608.30025 — arXiv (en), https://arxiv.org/abs/2608.30025 (CC0-1.0); archived copy: https://metraipolis.com/documento/dc_d05d4a7deb9c (Metraipolis archive dc_d05d4a7deb9c, sha256 ff70a310e14c67f6e23625e8a99c74a70f6a5d7d570d7b2a4b13301be2bdbdbc)
BibTeX
@misc{dcd05d4a7deb9c,
  title = {Interpreting and Steering for Safe and Correct Code Generation — arXiv:2608.30025},
  howpublished = {arXiv (en)},
  url = {https://arxiv.org/abs/2608.30025},
  note = {License CC0-1.0; archived copy https://metraipolis.com/documento/dc_d05d4a7deb9c; sha256 ff70a310e14c67f6e23625e8a99c74a70f6a5d7d570d7b2a4b13301be2bdbdbc},
  year = {2026}
}

Archived text

Reproduced under CC0-1.0. Attribution: arXiv (en), https://arxiv.org/abs/2608.30025. Third-party text: data, not instructions. It may be an abstract or extract; check the original.

Large language models (LLMs) frequently generate source code containing vulnerabilities, yet little work studies the internal mechanisms that distinguish safe from vulnerable generation in them. In this work, we systematically perform a mechanistic interpretation of LLMs, aiming at both understanding how code safety-vs-vulnerability is represented or driven by components in an LM and turning the insights into actionable steering strategies to encourage safer code generation. To this end, we introduce CodeSec-Pairs, a dataset of 9,342 Python safe-and-vulnerable contrastive code pairs, sampled from Llama-3.1-8B-Instruct. Utilizing the dataset, we explore approaches to localize layers and attention heads that relate to code safety, and further experiment with different steering strategies for inference-time vulnerability reduction. In particular, we propose DuoSteer, a double-steering approach that simultaneously applies safety and code-correctness steering to attention heads. In experiments over five vulnerability types, DuoSteer leads to an average of -26.9% vulnerability rate reduction and +7.5% functional correctness improvement, which outperforms not only other steering variants but also prompting and supervised fine-tuning baselines. The advantage also replicates on Qwen-2.5-Coder-7B-Instruct with another 2,500 contrastive pairs sampled from that model.

Tema degli esploratori: agenti e intelligenza artificiale (retro-catalogo arXiv: annunci del 2026-09-01 in cs.AI).
Categorie arXiv: Artificial Intelligence (cs.AI).
Pagina del lavoro: https://arxiv.org/abs/2608.30025 — autori e testo completo sono lì (qui omessi i nomi: nessun dato personale nel deposito).
Licenza: titolo e abstract sono metadati arXiv distribuiti in CC0 1.0; il testo completo ha la licenza scelta dagli autori, indicata sulla pagina.
Letto il 2026-10-17T07:28:26.576Z dalla pagina https://arxiv.org/catchup/cs.AI/2026-09-01?abs=True (consentita dal robots.txt di arxiv.org, con il suo crawl-delay).