On the Robustness of LLMs' Internal Representation of Code Correctness

πŸ“… 2026-08-08
πŸ“ˆ Citations: 0
✨ Influential: 0
πŸ“„ PDF
πŸ€– AI Summary
This study systematically investigates whether large language models (LLMs) internally encode robust representations of code correctnessβ€”a question left unresolved despite widespread use of LLM-generated code. By constructing program pairs that differ only by a single error and leveraging hidden state analysis, contrastive learning, and execution-free correctness assessment, the authors extract internal signals across diverse model configurations. Their findings reveal that no universally optimal signal extraction strategy exists, and merely isolating erroneous tokens does not enhance signal quality. These results indicate that the internal representation of correctness in LLMs is highly contingent on the specific extraction methodology employed, exhibiting strong configuration-dependent behavior rather than a stable, intrinsic encoding.
πŸ“ Abstract
Code generated by modern language models often reads naturally. Yet, it also often fails to implement what was asked. This should be no surprise, as research shows the models' own confidence signals are poorly calibrated with actual correctness. A promising way to assess correctness looks inside the model: by contrasting the hidden states of correct and incorrect programs, recent work captured an internal signal of code correctness that is able to judge candidate solutions better than the model's token-level or stated confidence, with no test execution. However, this signal was captured under one particular way, leaving open an important question: whether it reflects a robust property of the model or an artifact of that choice. We study this question systematically, varying how the signal is extracted from the model internals. Besides this, we also ask if the signal's quality is limited by the data used to extract it, by constructing program pairs that differ only in the fault that makes them incorrect. Our results show that no single configuration is best, and that isolating the fault does not help.
Problem

Research questions and friction points this paper is trying to address.

robustness
code correctness
internal representation
large language models
hidden states
Innovation

Methods, ideas, or system contributions that make the work stand out.

internal representation
code correctness
large language models
robustness
hidden states
πŸ”Ž Similar Papers
No similar papers found.
F
Francisco Ribeiro
New York University Abu Dhabi
S
Sohaila Abdulsattar
New York University Abu Dhabi
R
Renata Gonzalez
New York University Abu Dhabi
M
Mahmoud Kassem
New York University Abu Dhabi
Sarah Nadi
Sarah Nadi
Associate Professor, New York University Abu Dhabi
Mining Software RepositoriesAPI UsageSoftware ReuseEmpirical Software Engineering