Evaluating LLM Coding Capabilities: Hallucination, Engineering Discipline, and Context Governance

    Summary: This article explains why code that runs in a demo often fails to be maintainable in a real repository, and how to evaluate LLM coding capabilities systematically. It breaks assessment into four measurable layers—context fidelity, instruction and convention compliance, post-training engineering judgment, and self-repair quality—and outlines four common failure modes: hallucination, missing conventions, repair oscillation, and confidently wrong abstractions. It then presents a practical framework of read-only analysis, plan review, and controlled execution, along with context and knowledge governance, human-AI division of labor, and quality gates to keep code quality from degrading faster than a team can fix it.

    1. Background: Why “It Runs” Is Not the Same as “It Ships”

    After introducing AI coding tools into real development workflows, many teams run into a counterintuitive pattern: demos look smooth, but output becomes hard to maintain once it enters a real repository. The problem is not single-shot generation quality. It is that engineering constraints get ignored—commit conventions, dependency boundaries, error-handling agreements, and rollbackability. These fall under engineering discipline and must be explicitly reinforced during post-training. Otherwise, the model optimizes for goal completion without caring whether the path is auditable.

    Another underestimated problem is attention decay over long contexts. When the input spans dozens of files, several interface definitions, and prior discussions, the model tends to lose key constraints and produce call relationships and state transitions that look plausible but are wrong. These can escalate into factual errors. Such errors are more dangerous than syntax errors because they compile, pass shallow tests, and still bury defects in the architecture.

    2. Capability Layers: Turning “Is the Model Good?” into Four Measurable Things

    To evaluate a coding model, split the assessment into four layers and set acceptance criteria for each, instead of relying on a vague “usable or not.”

    1. Context fidelity: Within the given repository scope, can it consistently reference real symbols, configuration keys, and interface signatures without inventing dependencies?
    2. Instruction following and convention consistency: Does it respect existing commit granularity, naming conventions, directory structure, and testing requirements?
    3. Engineering judgment from post-training: When facing an error, does it locate the root cause first, or pile on patch-style changes?
    4. Self-repair quality: Does the fix minimize changes, include verification, and remain rollbackable?

    A sample assessment record can be very simple:

    1. case_id | context size | hallucinated symbol (yes/no) | convention violations | repair rounds | new defect introduced (yes/no)

    Running one regression pass with this table turns subjective impressions into comparable data and makes it easy to compare models and prompting strategies side by side.

    3. Typical Failure Modes and Root Causes

    The first is hallucination-driven failure. When information is insufficient, the model tends to fill gaps rather than admit uncertainty, generating nonexistent configuration keys, wrong version constraints, or even mixing up state machines for similar concepts. The mitigation is not a longer prompt. It is providing authoritative, retrievable context and requiring the model to explicitly output “to be confirmed” when evidence is missing.

    The second is missing-convention failure. Output is barely functional, but commits are messy, logging is absent, and exceptions are swallowed. This stems from training objectives biased toward outcome completion, with no penalty signal for engineering constraints.

    The third is repair-oscillation failure. A defect goes through three to five rounds without converging, and each round introduces new side effects. The criteria are straightforward: does the change scope expand each round, and are tests repeatedly loosened?

    The fourth is the “confident trap.” Unlike messy code, this output is neatly structured and well named, but hard-codes a wrong abstraction into a shared layer, making later investigation extremely costly. What teams really need to guard against is this low-frequency, high-damage output.

    4. Practical Framework: Analysis First, Plan Audit, Controlled Execution

    Split the interaction into three stages, each with clear deliverables and gates.

    Stage one: read-only analysis. Any write operation is prohibited. Require a list of issues, impact scope, dependencies, and risk points.

    1. Constraint: analysis only, no file modification
    2. Deliverables: root-cause hypotheses + impact scope + verification plan + items to be confirmed

    Stage two: plan review. A human audits the plan’s boundaries and rollback path, and execution begins only after confirmation. The value here is turning “model confidence” into checkable text.

    Stage three: controlled execution. Limit the file whitelist, limit the number of rounds, require each round to include verification commands and expected output, and retain one-click rollback.

    1. # Minimal constraints for controlled execution
    2. Allowed to modify: src/service/order_flow.*
    3. Prohibited to modify: shared abstraction layer, build scripts
    4. Each round must output: change summary / verification method / rollback point

    5. Context and Knowledge Governance

    Persist long-lived conventions as in-repository specification files and retrievable documents instead of relying on model memory. Documents should be short, verifiable, and include examples. For known historical misjudgments, lock them in with test cases rather than repeating natural-language reminders. On the retrieval side, prioritize authority: interface definitions, configuration schemas, and error-code tables should be precisely retrievable to reduce the model’s room for improvisation.

    Pair this with logging services and monitoring alerts so failed samples automatically flow back into regression cases, forming a closed loop. On the engineering side, container platforms can pin the build environment, and message queues can decouple long-running tasks, letting model output be verified in an isolated environment without polluting the main branch.

    6. Human-AI Division of Labor and Quality Gates

    Models are suited for retrieval, summarization, boilerplate code, test drafts, and documentation cleanup. Architecture decisions, shared-layer changes, and data migrations must remain human responsibilities. Recommended gates include static checks, unit tests, change-size thresholds, and dual-sign review. When repair rounds exceed a threshold or change scope keeps expanding, roll back to the analysis stage and redo it instead of continuing to prompt.

    7. Conclusion

    The right expectation for a coding model is to treat it as a high-throughput executor that needs constraints. The measure should shift from “can it generate” to “can it converge reliably under conventions and verifiability.” Only by insisting on analysis first, plan audit, and controlled execution—and by turning conventions into retrievable assets and automated gates—can teams enjoy efficiency gains without letting code rot outpace their ability to fix it.