Large language models (LLMs) have demonstrated strong performance on function-level code generation benchmarks, yet real-world software development increasingly demands class-level implementations that integrate multiple methods, attributes, and dependencies within authentic project contexts. This gap between benchmark performance and practical utility raises critical questions about LLMs' readiness for production code assistance, particularly regarding their ability to generalize across familiar and novel codebases.
We introduce a benchmark derived from real-world open-source repositories, comprising classes divided into seen and unseen partitions to evaluate generalization under practical conditions. We systematically examine how input specification completeness and retrieval-augmented generation affect class-level correctness across multiple state-of-the-art LLMs.
Our evaluation reveals a substantial performance gap: while LLMs achieve 84–89% correctness on synthetic benchmarks, they attain only 25–34% on real-world class tasks, with minimal distinction between familiar and novel codebases. Comprehensive documentation provides marginal improvements (1–3%), whereas retrieval augmentation yields greater gains (4–7%) by supplying concrete implementation patterns. Error analysis identifies AttributeError, TypeError, and AssertionError as dominant failure modes, with distinct patterns between synthetic and real-world scenarios.
These findings provide actionable insights for enhancing context modelling, documentation strategies, and retrieval integration in production code assistance tools.
Keywords:
1. Introduction
Large language models (LLMs) have demonstrated remarkable progress in code generation, enabling tools like GitHub Copilot (21) and Amazon CodeWhisperer (10) to assist developers in writing their code on various levels of granularity (Chen et al., 2021; Tao et al., 2025). However, existing benchmarks such as CoderEval (Yu et al., 2024a) and ClassEval (Du et al., 2023) primarily focus on either function-level generation or manually crafted class-level tasks. These benchmarks do not fully capture the complexities of real-world software projects, where developers frequently encounter interdependent classes, project-specific patterns, and the need to generalize to unseen codebases. The reliance on synthetic benchmarks creates a critical evaluation gap: if LLMs perform well on carefully constructed, self-contained tasks but fail on authentic production code with realistic dependencies and complexity, practitioners cannot reliably predict tool performance in actual development workflows. This disconnect between benchmark performance and real-world capability means developers may adopt LLM-based tools with inflated confidence, leading to productivity losses, increased debugging time, and potential integration of incorrect code into production systems. This gap raises a critical question: How well do LLMs generate class-level code for real-world projects, particularly when faced with unseen contexts? Addressing this question is essential for advancing LLM-assisted programming tools because it enables more accurate assessment of their practical capabilities, guides developers in setting appropriate expectations for tool reliability, and identifies specific technical limitations that must be overcome before these tools can be safely deployed in production environments where code correctness directly impacts software quality and development velocity.
Current research on LLM-based code generation has largely centred on function-level tasks, with benchmarks like HumanEval (Chen et al., 2021) and MBPP (Austin et al., 2021) evaluating standalone functions. While ClassEval (Du et al., 2023) introduced class-level evaluation, its manually crafted tasks do not reflect the intricacies of real-world projects. Specifically, synthetic benchmarks present several fundamental limitations: they typically feature self-contained classes with minimal external dependencies, whereas real-world code heavily relies on framework integrations, third-party libraries, and project-specific utilities; they use simplified test suites with straightforward assertions, while production code requires handling complex type systems, inheritance hierarchies, and dynamic attribute resolution; and they lack the evolutionary complexity of real codebases where classes must integrate with existing architectural patterns and legacy code. These differences mean that high performance on synthetic benchmarks does not guarantee success on realistic tasks, creating a false sense of LLM capabilities. Recent work on retrieval-augmented generation (RAG) for code (Yang et al., 2025; Tao et al., 2025) has shown promise in improving LLM performance by incorporating relevant context, but its application to class-level generation in real-world settings remains underexplored. Furthermore, studies on repository-level code generation (Tao et al., 2025) highlight the need for benchmarks that capture project-level dependencies, which are absent in existing evaluations.
We address the issues above by curating a new benchmark of real-world class-level code from open-source projects, categorized as 'seen' (classes from repositories created before model training cutoffs, likely encountered during training) and 'unseen' (classes from repositories created after training cutoffs, guaranteeing they were not in training data). Our evaluation framework assesses LLM performance across different docstring variants, generation strategies, and RAG-augmented setups. We systematically analyze the impact of docstrings, the effectiveness of RAG, and the types of errors that arise in generated code, providing insights into the strengths and limitations of current LLMs. More specifically, we investigate the following research questions:
RQ1 (Real-World Performance): How do LLMs perform on class-level code generation in real-world projects compared to synthetic benchmarks? We find that LLMs achieve 84–89% correctness on synthetic benchmarks but only 24–35% on real-world code. Models show nearly identical performance on seen and unseen real-world data.
RQ2 (Docstring Impact): Does the presence of docstrings improve the functional correctness of LLM-generated classes? Our finding shows that complete docstrings provide improvements of 1–3% in correctness, in some cases, although this improvement is not frequent enough to gain statistical significance.
RQ3 (RAG for Unseen Code): Can retrieval-augmented generation (RAG) using seen data improve LLM performance on unseen class-level tasks? We find that RAG provides substantial benefits of 4–7% specifically when documentation is incomplete (partial docstrings), but minimal value with complete documentation. This shows that RAG helps by providing concrete implementation examples when specifications lack implementation details.
RQ4 (Error Analysis): What are the most common errors in LLM-generated class-level code? We find that AttributeError, TypeError, and AssertionError account for 84% of all failures. Synthetic benchmarks show assertion-dominated failures while real-world code shows attribute-and-type-dominated failures, and RAG operates through error substitution, reducing logic failures while occasionally introducing dependency errors.
By answering the above RQs, this paper makes the following contributions:
- A curated dataset of real-world class-level code from open-source projects, categorized as seen and unseen.
- A systematic evaluation of LLM performance on class-level generation, comparing real-world projects to synthetic benchmarks.
- An analysis of the impact of docstrings and RAG on functional correctness and error types.
- Insights into common errors and practical implications for improving LLM-assisted programming tools.
Paper Structure
The remainder of this paper is organized as follows: Section 2 discusses related work and background. Section 3 describes the design of our benchmark and the overall view of the research methodology. Sections 4, 5, 6, and 7 address RQs 1, 2, 3, and 4, respectively. Section 8 discusses the implications of our findings. Section 9 describes some of the limitations of our study and outlines future directions. Section 10 discusses the threats to validity. Finally, Section 11 concludes the paper.
2. Background and Related Work
2.1. Large Language Models for Code Generation
Large Language Models (L