mlsanityData to 14 Oct 2026

Mechanistic Interpretability of Code Correctness in LLMs via Sparse Autoencoders

arXiv 2510.02917 ↗First posted 3 Oct 2025cs.SE cs.LGcited by 5

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

  1. 2021Program Synthesis with Large Language Modelscited by 3,637
  2. 2013Distributed Representations of Words and Phrases and their Compositionalitycited by 3,474
  3. 2024Gemma 2: Improving Open Language Models at a Practical Sizecited by 1,998
  4. 2024Refusal in Language Models Is Mediated by a Single Directioncited by 1,032
  5. 2022Toy Models of Superpositioncited by 971
  6. 2023The Linear Representation Hypothesis and the Geometry of Large Language Modelscited by 716
  7. 2023The Geometry of Truth: Emergent Linear Structure in Large Language Model Representations of True/False Datasetscited by 712
  8. 2023Dissecting Recall of Factual Associations in Auto-Regressive Language Modelscited by 528
  9. 2024Gemma Scope: Open Sparse Autoencoders Everywhere All At Once on Gemma 2cited by 394
  10. 2024Do I Know This Entity? Knowledge Awareness and Hallucinations in Language Modelscited by 115
  11. 2022Probing Pretrained Models of Source Codecited by 26
  12. 2022Follow-up Attention: An Empirical Study of Developer and Neural Model Code Explorationcited by 5
2 more
  1. 2024A Critical Study of What Code-LLMs (Do Not) Learncited by 4
  2. 2025LLMs are Bug Replicators: An Empirical Study on LLMs' Capability in Completing Bug-prone Codecited by 1

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2026: 5.

5 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026CodeCircuit: Toward Inferring LLM-Generated Code Correctness via Attribution Graphs
  2. 2025Correctness Assessment of Code Generated by Large Language Models Using Internal Representations
  3. 2026Memorization Diagnostics for Code LLMs Should be Scale-Aware
  4. 2026How Robustly do LLMs Understand Execution Semantics?
  5. 2025LeetCodeDataset: A Temporal Dataset for Robust Evaluation and Efficient Training of Code LLMs
  6. 2025Artificial or Just Artful? Do LLMs Bend the Rules in Programming? ↗
  7. 2025Teaching Your Models to Understand Code via Focal Preference Alignment
  8. 2026Efficiency Hallucination: Formalizing and Measuring Behavioral Calibration in LLM-Based Code Optimization