Testing Large Language Models on Code: A Practical Guide to Avoiding Common Pitfalls
This article examines why running a demo is not the same as modifying a real engineering project, and presents a four-dimension framework for evaluating a model's engineering usability: plan adherence, error attribution, convergence efficiency, and presentation fidelity. It also outlines a reproducible workflow using constraint-based prompts, a minimal feedback loop, change-size circuit breakers, and a layered evaluation set, followed by suggestions for operationalizing the process on Baidu AI Cloud.
1. Background: Why a Working Demo Does Not Mean a Maintainable Project
Asking a large language model to modify a complex, dependency-heavy system-level project is a completely different class of task from asking it to generate a runnable snippet. The former requires long-chain, multi-step changes under existing code constraints, with every step gated by compilation and tests. The latter only needs to be locally correct.
In one typical run, the task was broken into six major steps, each with a defined scope of changes and a verification method. Several models executed the same codebase and the same plan. Most passed on the first attempt; the main quality difference showed up in whether the model proactively asked for clarification when it hit uncertain information.
The weaker models exhibited two recurring failure patterns:
- Misattributed errors: blaming compilation failures on external factors such as “cache issues” and asking the user to provide a solution.
- Ineffective convergence: making scattered small edits without establishing a feedback loop, producing thousands of meaningless changes in a short time and still failing verification.
The root cause is not insufficient compute. It is a lack of engineering-grade problem localization and self-verification. For developers, recognizing and avoiding these behaviors is more valuable than comparing leaderboard scores.
2. Evaluation Framework: Four Dimensions of Engineering Usability
2.1 Plan Adherence
Check whether the model follows the predefined steps strictly and whether it moves to the next step before verification passes. A qualified executor treats a verification failure as a blocking condition, not a step that can be skipped.
2.2 Error Attribution
When compilation or tests fail, the model should first suspect its own output, read the full error message, locate the specific file and line number, and then propose a minimal fix. Blaming the environment, cache, or toolchain is a hallucinated attribution.
2.3 Convergence Efficiency
The metric here is the number of effective changes: the proportion of edits that actually move verification forward. Shotgun-style edits make the change count explode while the pass rate stays flat, which is a clear signal of collapsing efficiency.
2.4 Presentation and Fidelity
For visualization and graphics tasks, check whether the model honors the style constraints in the requirements, follows basic common sense (such as reasonable physical layout), and whether the training process actually converges.
3. Practical Method: Turning Trial and Error into a Reproducible Process
3.1 Use Constraint-Based Prompts to Close Attribution Loopholes
State the environment facts explicitly at the start of the plan to reduce the room for the model to invent external causes:
Constraints:1. There are no cache-related failures in the current environment; compilation failures are 100% caused by code errors.2. Each step must pass compilation and tests before moving to the next step.3. Do not modify files belonging to later steps while verification has not passed.4. Keep each change to no more than 3 files, and attach an error localization note after the change.
3.2 Build a Minimal Feedback Loop
Force the model to run the cycle “read the error, localize, apply a minimal fix, re-run verification,” and feed each verification output into the next step. Without this loop, any model degrades into random search.
3.3 Add a Change-Size Circuit Breaker
When a single step exceeds a threshold (for example, dozens of changes) and verification still fails, roll back immediately and reduce the task granularity. This is more economical than letting the model churn for hours.
3.4 Use a Layered Evaluation Set
Split evaluation into three layers: engineering changes, algorithm training, and graphics presentation, each with its own pass criteria. This avoids letting a single “does it look good” judgment mask gaps in engineering capability.
4. Operationalizing on a Platform
When deploying intelligent coding and model capabilities on Baidu AI Cloud, the recommended approach is to turn the workflow above into engineering standards: use a container platform to provide a reproducible build environment, use logging and monitoring with alerting to capture the full output of every verification run, and use object storage to archive versioned artifacts and evaluation reports. This keeps experiments consistent and shifts model selection from subjective impressions to data-driven decisions.
5. Conclusion
Whether a model is suitable for engineering changes depends not on demo quality but on honest error attribution, strict step adherence, and efficient convergence. Making the verification loop, the change circuit breaker, and layered evaluation part of the process is the genuinely reusable lesson.
