TL;DR
DocGenBench is a new benchmark that evaluates code documentation agents not by how much their output "looks" like human writing, but by whether that documentation is actually useful for reconstructing functional code. By measuring how well an independent LLM can regenerate functions from generated docstrings to pass unit tests, the authors provide a "functional utility" metric that exposes the flaws in traditional lexical similarity scores.
What Problem Does This Paper Address?
We are currently in an explosion of automated documentation tools, yet we are still grading them using the equivalent of a spelling test. Traditional metrics like BLEU or ROUGE measure lexical similarity—how many words a generated docstring shares with a human-written reference.
The problem? High similarity doesn't guarantee high utility. A docstring can be grammatically perfect and "human-like" while missing the critical technical details needed to actually implement the function. Conversely, an AI might generate a terse, technical summary that is ugly to a human reader but perfectly enables another AI to reconstruct the code. This paper addresses the lack of an objective, execution-based framework to measure the practical utility of documentation in a repository-scale context.
Methods
The authors propose a three-stage pipeline called DocGenBench:
- Documentation Generation: An agent (the system under test) traverses a software repository and generates docstrings for functions, using the full repository context (imports, class hierarchies, etc.).
- Code Regeneration: A "fixed evaluator" LLM (like GPT-5-mini or Qwen3) is given the generated docstring and the file-level context (but not the original function body). It must then attempt to rewrite the function body from scratch.
- Functional Testing: The regenerated code is inserted back into the repository and executed against existing unit tests.
The core metric is pass@k, which calculates the probability that at least one of $k$ generated code samples passes all tests.
A standout technical detail is their Mock Implementation Filtering. To ensure the benchmark isn't "cheating" with trivial tests, they replace function bodies with empty "stubs." If the tests still pass, the task is discarded as "vacuous." This ensures every task in the benchmark requires a non-trivial functional contract to be fulfilled.
Datasets
The benchmark consists of 2,924 tasks derived from 28 Python repositories.
- 10 Popular Repos: Projects with >100 GitHub stars (e.g.,
requests,pytube). - 18 Random Repos: A diverse set of smaller projects to ensure the benchmark isn't just measuring "memorization" of famous codebases.
This repository-level approach is a significant step up from previous "round-trip" methods that only looked at isolated functions without considering cross-file dependencies.
Key Insights and Ideas
- The "Lexical Gap": There is a very weak correlation (below 0.12) between lexical similarity (how much the doc looks like the original) and functional utility (whether the code works). This suggests that optimizing for "human-like" text might actually be a distraction for technical documentation agents.
- AI-to-AI Communication: The benchmark treats documentation as a communication channel between a "producer" (the doc agent) and a "consumer" (the coder/LLM). The results show that AI-generated documentation can sometimes functionally outperform original human-written docstrings for code synthesis tasks.
- No Self-Preference Bias: Interestingly, the authors found that evaluator LLMs didn't necessarily perform better when implementation was based on documentation generated by a model from their own "family." This suggests the benchmark measures genuine informational completeness rather than stylistic alignment.
- Cost Efficiency: Computing these functional metrics is significantly cheaper (~$10 for the whole benchmark) compared to "LLM-as-judge" approaches, which can cost ten times as much.
Key Results
The authors compared two major open-source agents: RepoAgent and OSA.
- RepoAgent consistently outperformed OSA across almost all settings, achieving a pass@1 of up to 0.83 when evaluated by Qwen3.
- Improvement over "Default": Both agents significantly improved code reconstruction success compared to the original "default" docstrings found in the repositories.
- Stability: The ranking of the documentation systems remained stable regardless of which LLM was used as the evaluator, proving the benchmark's robustness.
Limitations and Future Work
- Test Quality Dependency: The benchmark is only as good as the repository's unit tests. If a test suite is "weak" (low coverage), it might pass buggy code, inflating the scores.
- Style vs. Substance: The metric explicitly ignores "human-centric" qualities like pedagogy, tone, or narrative flow. A docstring that is great for an LLM might be frustrating for a human junior developer to read.
- Code Leakage: While the authors manually checked for "copy-pasting" of code into docstrings, they acknowledge that more automated filters for "code-in-docstring" detection are needed for future iterations.
- Language Support: Currently, the benchmark is focused on Python. Expanding to other languages with different package management and testing cultures is a logical next step.
Summary updated