Evaluating Large Language Models for Code: Hallucinations and Post-Training Gaps
This article examines why large language models that perform well in demos often fail to deliver reliable engineering results in real repositories. Based on long-term use of different general-purpose model versions, it defines four key capability areas for evaluating AI coding tools—engineering convention adherence, long-context attention, factual consistency, and code self-repair—and analyzes how each one fails. It then presents a reusable workflow: restrict the model to analysis, produce a proposal for human review before any changes, and apply context slicing, constraint prompts, regression checks, and change tracking. It also covers chain-of-thought self-doubt, its cost and latency impact, and metric recommendations for tool selection and evaluation.
In real development workflows, connecting large language models to codebases, documentation, and environment configuration has shifted from experimentation to routine practice. Yet many teams quickly discover a gap: a model can run a demo but struggles to deliver stable engineering results. This article uses long-term observations across different versions of general-purpose large models to distill four key capabilities for evaluating AI coding tools—engineering convention adherence, long-context attention, factual consistency, and code self-repair—and examines the failure mode and root cause of each. It then outlines a reusable usage pattern: strictly limit the model to the analysis phase, have it produce a proposal first, require human review, and only then allow changes; combined with context slicing, constraint prompts, regression checks, and change tracking, this turns an uncontrollable generation process into an auditable engineering workflow. The article closes by discussing the phenomenon of repeated chain-of-thought self-questioning and its impact on cost and latency, along with recommendations for team selection and evaluation metrics. Readers will get a practical evaluation checklist and collaboration guidelines that improve the success rate and maintainability of AI-assisted development without relying on any specific product.
1. Background: Why “Demo-Ready” Does Not Mean “Delivery-Ready”
Many AI coding tools perform well in demo environments, but problems surface once they are connected to a real repository. Real repositories typically have three characteristics: deep directory hierarchies, heavy legacy baggage, and many implicit conventions. The model is not facing a clean, well-defined problem but a large body of coupled code and documentation with inconsistent naming, missing comments, and even outdated content. In this situation, a model’s “seemingly reasonable” output often conflicts with the project’s actual constraints, so changes either cannot be merged or introduce new defects after merging.
Therefore, evaluating these tools should not focus only on the fluency of a single-turn answer; it should examine stability across multiple turns, long contexts, and noisy environments. The following four capabilities form the baseline framework for judging whether an AI coding assistant is “good enough.”
2. Capability One: Engineering Convention Adherence and Post-Training Quality
Engineering discipline is the first threshold that separates a “general-purpose chat model” from a “usable coding model.” Concretely, it shows up as: whether the model respects the existing directory structure and layering conventions; whether it submits changes in the project’s established style; whether its commit messages accurately summarize the scope and impact of the change; and whether it introduces unreviewed dependencies or rewrites public interfaces on its own initiative.
Models with insufficient post-training commonly show a pattern of “goal achieved, process disordered”: tests may pass, but logic is forced into the wrong layer; an error may be fixed, but a necessary validation is deleted along the way. The danger of such changes is that short-term metrics look good while long-term maintenance costs rise sharply. During evaluation, it is advisable to add a “convention compliance” check—for example: whether changes are confined to the appropriate modules, whether unnecessary dependencies were added, and whether interfaces remain backward compatible. A simple automation script can enforce hard blocks:
# Example: check whether a change touched directories or dependency manifests it should notgit diff --name-only | grep -E '^(src/core|public_api)/' && echo "Out-of-bounds change, manual review required"git diff -- '*dependency_manifest*' && echo "Dependency change, architecture review required"
3. Capability Two: Long-Context Attention and Hallucination Control
Reading code and documentation is essentially retrieval and reasoning over long contexts. The direct consequence of scattered attention is that the model “mixes up names and references” in long text: attaching module A’s interface to module B, or citing a call relationship that does not exist. More insidious are factual errors—the model holds an incorrect understanding of a general concept, protocol, or algorithm, and even if you explicitly correct it in the prompt, it may revert to the old mistake in later steps.
Controlling hallucinations cannot rely on “reminding a few more times”; it requires process constraints:
- Context slicing: split material by module and by call chain, giving the model one clear boundary at a time;
- Evidence citation: require the model to annotate the source file and line range for every conclusion; output without evidence is treated as invalid;
- Cross-validation: key conclusions are verified by a second
