A Preliminary Study on Explaining Risk of Code Changes using LLM-Based Prediction Models
Predictions by machine learning (ML) and artificial intelligence
(AI) models are often received skeptically unless they are paired
with intelligible explanations. In the context of just-in-time de-
fect prediction, highlighting small portions of a software change
(diff )—beyond rule-based lints—where risk may be concentrated
has not yet been extensively investigated. In this work, we leverage
attention weights from an LLM-based Diff Risk Score (DRS) model
to highlight parts of a diff that the model focuses on when pre-
dicting risk. We aggregate token-level attention into interpretable
code units (lines, hunks, and files), and present the top-𝐾 units
to developers as a lightweight form of guidance during code re-
view. We evaluate our approach using expert-labeled changes that
have caused real outages. Results show that the highlighted snip-
pets cover expert-labeled outage-causing change lines 53.85% of the
time when highlighting the top-2 hunks, while requiring developers
to review 26.28% of the changed lines on average. Because atten-
tion is produced during standard model inference, the approach is
scalable for large development workflows and can be surfaced in
the code review UI with low additional latency.