Hierarchical context improves LLM code summaries, arXiv study finds
Researchers report that prompts enriched with class- and module-level documentation produce code summaries closer to developer-written documentation across several large language models.
In plain words
Large language models can write short explanations of what code does, but they usually see only the function in front of them. The authors tested what happens when the models also see documentation from the surrounding class or module. Summaries improved, though by different amounts depending on the model.
What was announced
In a paper posted to arXiv, the authors describe an in silico study in which they varied how much of a program's hierarchy — function, class, and module level — was visible to several LLMs asked to generate code-level documentation. They compared the resulting summaries against existing documentation, which they treat as a proxy for developer intent. According to the paper, prompts that included documentation-aware context at the class or module level consistently produced summaries closest to the original documentation.
The reported gains over the baseline were statistically significant across models, but the effect sizes varied: negligible for DeepSeek, weak for GPT-4o-mini, and medium for Gemini. The authors note the study covers only immediate hierarchical context; call-graph traversal and cross-module dependency context were excluded and left to future work. They position the findings as a step toward better automated documentation tools and stronger LLM reasoning over codebases for tasks such as code retrieval.
What it does not show
- The evidence is limited to the paper's abstract, so the study's methods, datasets, and full results cannot be verified from the supplied passages.
- The study is described as in silico, and the abstract does not report testing with human developers or in production settings.
- The abstract does not name all models tested beyond DeepSeek, GPT-4o-mini, and Gemini, and gives no absolute quality numbers.
Sources
Source-support review completed 28 Nov 2026. This story was drafted with AI assistance and checked against retained source passages. Automated checking is not independent verification.
Coverage: arXiv: abstract.
Updates and corrections
No corrections so far.
First published 28 Nov 2026
New to the subject? AI from the Ground Up starts from the beginning.