Surgical Repair of Insecure Code Generation in LLMs
Not on the map. Why?
Abstract (arXiv)
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.
Key facts. Cited by 1 paper in the map (data through 7 Oct 2026). Builds on 32 of its 39 references that are in the map. First posted on arXiv 17 Apr 2026.
Builds on
32 of 39 references.
References · 32
- 2022Locating and Editing Factual Associations in GPTcited by 2,609
- 2023Sparse Autoencoders Find Highly Interpretable Features in Language Modelscited by 1,359
- 2022Interpretability in the Wild: a Circuit for Indirect Object Identification in GPT-2 smallcited by 1,130
- 2024Refusal in Language Models Is Mediated by a Single Directioncited by 960
- 2023Steering Language Models With Activation Engineeringcited by 824
- 2022Discovering Latent Knowledge in Language Models Without Supervisioncited by 733
- 2019Designing and Interpreting Probes with Control Taskscited by 608
- 2023Eliciting Latent Predictions from Transformers with the Tuned Lenscited by 579
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
- 2021Causal Abstractions of Neural Networkscited by 401
- 2024LLMs Know More Than They Show: On the Intrinsic Representation of LLM Hallucinationscited by 230
- 2023How does GPT-2 compute greater-than?: Interpreting mathematical abilities in a pre-trained language modelcited by 199
20 more
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2025Emergent Misalignment: Narrow finetuning can produce broadly misaligned LLMscited by 158
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
- 2023Explaining grokking through circuit efficiencycited by 105
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 87
- 2025Model Organisms for Emergent Misalignmentcited by 84
- 2023How Secure is Code Generated by ChatGPT?cited by 77
- 2025Convergent Linear Representations of Emergent Misalignmentcited by 66
- 2025School of Reward Hacks: Hacking harmless tasks generalizes to misaligned behavior in LLMscited by 58
- 2025Thought Crime: Backdoors and Emergent Misalignment in Reasoning Modelscited by 57
- 2024Constrained Decoding for Secure Code Generationcited by 35
- 2024Prompting Techniques for Secure Code Generation: A Systematic Investigationcited by 33
- 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 31
- 2025Compromising Honesty and Harmlessness in Language Models via Deception Attackscited by 17
- 2025Guiding AI to Fix Its Own Flaws: An Empirical Study on LLM-Driven Secure Code Generationcited by 12
- 2025Emergent misalignment as prompt sensitivity: A research notecited by 5
- 2025The Devil in the Details: Emergent Misalignment, Format and Coherence in Open-Weights LLMscited by 4
- 2023Measuring the Knowledge Acquisition-Utilization Gap in Pretrained Language Modelscited by 3
- 2026Can Adversarial Code Comments Fool AI Security Reviewers -- Large-Scale Empirical Study of Comment-Based Attacks and Defenses Against LLM Code Analysiscited by 2
- 2025Even Heads Fix Odd Errors: Mechanistic Discovery and Surgical Repair in Transformer Attentioncited by 1
Built on by
Citing papers per year: 2026: 1.
1 paper.