LLM Selection and Planning for Programming Tasks: A Practical Engineering Guide
This article explains how to choose and operationalize large language models for coding tasks. It covers evaluation dimensions, building a business-specific evaluation set, task-tier routing, quality gates, context management, cost and reliability controls, common pitfalls, and an action checklist. The goal is to make model selection a measurable, reproducible engineering process.
1. Why Programming Tasks Need Separate Planning
Programming tasks differ significantly from general question answering in their requirements for models. Code must satisfy syntax and type constraints, changes must remain consistent with the existing engineering structure, and errors often surface only at runtime or during testing. As a result, a model that performs well in general conversation may not reliably complete multi-file changes, defect localization, or test completion. Teams need to break “which model to choose” down into “which types of tasks should be assigned to which types of models, and what acceptance criteria should be used.”
2. Evaluation Dimensions to Clarify Before Selection
Evaluation can usually be organized around six dimensions:
- Code correctness: whether generated code can pass compilation, unit tests, and boundary cases.
- Engineering understanding: whether the model can read directory structures, identify module dependencies, and make changes in the existing style.
- Long-context handling: whether the model can preserve key constraints when facing thousands of lines of code or multiple technical documents.
- Instruction following and tool use: whether the model can output in the agreed format and correctly invoke external capabilities such as retrieval and execution.
- Latency and cost: whether response time and token consumption per request fit interactive or batch scenarios.
- Deployment and compliance: whether data can leave the internal network and whether enterprise audit and data retention requirements are met.
Public leaderboards can serve as an initial screening reference. However, leaderboard questions often differ from the distribution of real business code. Scores only indicate a model’s relative position on a specific test set and cannot directly represent performance on your own business tasks.
3. Building an In-House Evaluation Set
The evaluation set should come from real business scenarios. It is recommended to sample from historical tickets, merged code changes, and production defects. Each sample should include input context, expected behavior, and a verification method.
Illustrative code (pseudocode):
for case in eval_set:prompt = build_prompt(case.context, case.instruction)output = model.generate(prompt, temperature=0)patch = apply_to_sandbox(case.repo_snapshot, output)result = run_tests(patch, case.test_suite)record(model.name, case.id, result.passed, latency, tokens)
Acceptance should be based on executable results rather than subjective human scoring. After each model version update, rerun the same set of cases to obtain comparable trend data. Fixed temperature parameters and a fixed snapshot environment can reduce random fluctuations in results.
4. Model Routing by Task Tier
Different tasks have different risks and complexity, and the appropriate approach varies. A common tiering approach is as follows:
- Low-risk, high-frequency tasks: completing comments, generating boilerplate code, and performing format conversion. Models with low latency and low cost are suitable.
- Medium-complexity tasks: single-file feature implementation, unit test generation, and simple defect fixes. These require stronger code understanding.
- High-risk tasks: cross-module refactoring and changes involving permissions, funds, or data consistency. Models with stronger reasoning capabilities should be selected, together with human review.
The routing layer can make decisions based on task tags, code change scope, and historical success rates. Routing rules themselves should also be included in evaluation and calibrated regularly based on results.
5. Quality Gates for Engineering Implementation
Before model output enters the main branch, it should pass multiple layers of checks:
- Static checks: formatting, type checking, and dependency scanning.
- Automated tests: unit tests and integration tests must all pass.
- Change size limits: when a single generated change exceeds a threshold, it must be split or confirmed by a human.
- Human review: changes involving security, data, and core paths must be confirmed by an owner.
Context management also affects results. Providing only file fragments relevant to the task and clearly stating constraints—such as interface signatures, compatibility requirements, and error handling conventions—is usually more stable than putting the entire code repository into the context. The longer the context, the higher the probability that key information will be ignored. Therefore, priority should be given to ensuring the relevance and completeness of information.
6. Cost and Stability Governance
Cost control can start from three areas: caching results of repeated requests, limiting the maximum number of tokens per task, and scheduling batch tasks during off-peak business hours.
For stability, timeout and retry policies should be set to avoid unlimited retries of failed requests that waste resources. At the same time, prepare a degradation plan for model services. For example, when the primary model is unavailable, switch to a slightly weaker but available backup model, and record quality changes during the degradation period.
It is recommended to continuously monitor the following metrics: first-pass rate, average repair rounds, manual rework rate, cost per task, and P95 latency. These metrics reflect real value better than a one-time demo.
7. Common Pitfalls
First, making all selection decisions based on a single leaderboard while ignoring differences between business tasks and leaderboard questions. Second, neglecting data compliance and sending sensitive code to services that have not been evaluated. Third, focusing only on generation speed without tracking rework and repair costs. Fourth, treating model output as a reliable conclusion without testing and review.
8. Action Checklist
- Review programming tasks from the past three months and classify them by type and risk level.
- Build an evaluation set of no fewer than one hundred cases from real samples and fix the acceptance scripts.
- Compare two or three candidate solutions under the same conditions and record pass rate, latency, and cost.
- Develop tiered routing rules based on comparison results and connect them to quality gates.
- Retest once per quarter and adjust the strategy as model versions and business needs change.
Model capabilities change quickly. What remains stable and reusable is the evaluation process itself. By turning model selection into a measurable and reproducible engineering activity, teams can make informed decisions among quality, cost, and risk.
