Mechanistic Interpretability of Code Correctness in LLMs via Sparse Autoencoders
On the map: Mechanistic interpretability → Knowledge and representations inside LLMs
Abstract (arXiv)
As Large Language Models become integral to software development, with substantial portions of AI-suggested code entering production, understanding their internal correctness mechanisms becomes critical for safe deployment. We apply sparse autoencoders to decompose LLM representations, identifying directions that correspond to code correctness. We select predictor directions using t-statistics and steering directions through separation scores from base model representations, then analyze their mechanistic properties through steering, attention analysis, and weight orthogonalization. We find that code correctness directions in LLMs reliably predict incorrect code, while correction capabilities, though statistically significant, involve tradeoffs between fixing errors and preserving correct code. Mechanistically, successful code generation depends on attending to test cases rather than problem descriptions. Moreover, directions identified in base models retain their effectiveness after instruction-tuning, suggesting code correctness mechanisms learned during pre-training are repurposed during fine-tuning. Our mechanistic insights suggest three practical applications: prompting strategies should prioritize test examples over elaborate problem descriptions, predictor directions can serve as error alarms for developer review, and these same predictors can guide selective steering, intervening only when errors are anticipated to prevent the code corruption from constant steering.
Key facts. Cited by 5 papers in the map (data through 14 Oct 2026). Placed in Knowledge and representations inside LLMs, one of 13 directions in Mechanistic interpretability. Builds on 14 of its 20 references that are in the map. First posted on arXiv 3 Oct 2025.
Builds on
14 of 20 references.
References · 14
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2013Distributed Representations of Words and Phrases and their Compositionalitycited by 3,474
- 2024Gemma 2: Improving Open Language Models at a Practical Sizecited by 1,998
- 2024Refusal in Language Models Is Mediated by a Single Directioncited by 1,032
- 2022Toy Models of Superpositioncited by 971
- 2023The Linear Representation Hypothesis and the Geometry of Large Language Modelscited by 716
- 2023The Geometry of Truth: Emergent Linear Structure in Large Language Model Representations of True/False Datasetscited by 712
- 2023Dissecting Recall of Factual Associations in Auto-Regressive Language Modelscited by 528
- 2024Gemma Scope: Open Sparse Autoencoders Everywhere All At Once on Gemma 2cited by 394
- 2024Do I Know This Entity? Knowledge Awareness and Hallucinations in Language Modelscited by 115
- 2022Probing Pretrained Models of Source Codecited by 26
- 2022Follow-up Attention: An Empirical Study of Developer and Neural Model Code Explorationcited by 5
Built on by
Citing papers per year: 2026: 5.
5 papers.
- 2026Latent Programming Horizons in Coding Agentscited by 1
- 2026On the Robustness of LLMs' Internal Representation of Code Correctnesscited by 1
- 2026GeoLAN: Geometric Learning of Latent Explanatory Directions in Large Language Modelscited by 0
- 2026Backdooring Sparse Autoencoderscited by 0
- 2026What Do Sparse Autoencoder Feature Discovery Scores Identify? From Activations to Interventionscited by 0
- 2026What Do Sparse Autoencoder Feature Discovery Scores Identify? From Activations to Interventions11 Oct 2026
- 2026Backdooring Sparse Autoencoders5 Oct 2026
- 2026On the Robustness of LLMs' Internal Representation of Code Correctness8 Aug 2026
- 2026Latent Programming Horizons in Coding Agents6 Jul 2026
- 2026GeoLAN: Geometric Learning of Latent Explanatory Directions in Large Language Models19 Mar 2026
Similar, not cited
Close in wording, no citation either way
- 2026CodeCircuit: Toward Inferring LLM-Generated Code Correctness via Attribution Graphs
- 2025Correctness Assessment of Code Generated by Large Language Models Using Internal Representations
- 2026Memorization Diagnostics for Code LLMs Should be Scale-Aware
- 2026How Robustly do LLMs Understand Execution Semantics?
- 2025LeetCodeDataset: A Temporal Dataset for Robust Evaluation and Efficient Training of Code LLMs
- 2025Artificial or Just Artful? Do LLMs Bend the Rules in Programming? ↗
- 2025Teaching Your Models to Understand Code via Focal Preference Alignment
- 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimization