Mechanistic Interpretability of Code Correctness in LLMs via Sparse Autoencoders

Kriz Tahimic, Charibeth Cheng
10/3/2025
cs.SEcs.LG

No confident code implementation found for this paper. 3 possible matches can be shown below.

Abstract

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 3 weaker matches are hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{tahimic2025mechanistic,
  title  = {Mechanistic Interpretability of Code Correctness in LLMs via Sparse Autoencoders},
  author = {Kriz Tahimic and Charibeth Cheng},
  year   = {2025},
  eprint = {2510.02917},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2510.02917v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2510.02917.svg)](https://codeofpaper.com/paper/2510.02917)

Discussion