A surgical repair for LLM insecure code generation
Surgical Repair of Insecure Code Generation in LLMs
The researchers find that LLMs generating insecure code is not a knowledge deficit: the same models can correctly identify and explain vulnerabilities when asked directly, and the authors call this gap the Format-Reliability Gap. Mechanism analysis shows that safety representations are encoded from the earliest layers but remain computationally inert until the final layer, where format compliance requirements compete with safety representations. Because the failure is confined to a single layer, vulnerability-tailored steering vectors can reduce insecure generation by up to 74% with negligible overhead. This mechanism and repair method hold across five models, three architecture families and six vulnerability types, and the authors accordingly argue that insecure code generation is an interpretability problem rather than a training artifact.