Surgical Repair of Insecure Code Generation in LLMs

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Sandoval, Gustavo, Dolan-Gavitt, Brendan, Garg, Siddharth
Format: Preprint
Veröffentlicht: 2026
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866908975609413632
author Sandoval, Gustavo
Dolan-Gavitt, Brendan
Garg, Siddharth
author_facet Sandoval, Gustavo
Dolan-Gavitt, Brendan
Garg, Siddharth
contents Large language models write production code, and yet they routinely introduce well-known vulnerabilities. We show that this is not a knowledge deficit: the same models that generate insecure code, correctly identify and explain the vulnerability when asked directly, this is a gap we call the Format-Reliability Gap. Mechanistic analysis reveals the cause: security representations are encoded from the earliest layers but remain computationally inert until the final layer, where format-compliance demands compete with them. Because the failure is localized to a single layer, per-vulnerability steering vectors reduce insecure generation by up to 74% with negligible overhead. The mechanism and the fix generalize across five models, three architecture families, and six vulnerability types, suggesting insecure code generation is an interpretability problem, not a training artifact.
format Preprint
id arxiv_https___arxiv_org_abs_2604_16697
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Surgical Repair of Insecure Code Generation in LLMs
Sandoval, Gustavo
Dolan-Gavitt, Brendan
Garg, Siddharth
Cryptography and Security
Machine Learning
Large language models write production code, and yet they routinely introduce well-known vulnerabilities. We show that this is not a knowledge deficit: the same models that generate insecure code, correctly identify and explain the vulnerability when asked directly, this is a gap we call the Format-Reliability Gap. Mechanistic analysis reveals the cause: security representations are encoded from the earliest layers but remain computationally inert until the final layer, where format-compliance demands compete with them. Because the failure is localized to a single layer, per-vulnerability steering vectors reduce insecure generation by up to 74% with negligible overhead. The mechanism and the fix generalize across five models, three architecture families, and six vulnerability types, suggesting insecure code generation is an interpretability problem, not a training artifact.
title Surgical Repair of Insecure Code Generation in LLMs
topic Cryptography and Security
Machine Learning
url https://arxiv.org/abs/2604.16697