A Practical Framework for Selecting Lightweight LLMs in Engineering Tasks
This article presents a role-based framework for selecting large language models in software engineering workflows. It introduces a clear division between planning models, which handle complex reasoning and design, and executor models, which perform well-defined, verifiable tasks. The guide details how to establish reproducible evaluation sets, measure key metrics such as first-try pass rate and out-of-scope modification rate, and implement routing strategies with fallback mechanisms. It also covers common failure modes, including over-engineering and instruction drift, and provides practical countermeasures for production environments.
1. Background: Why Task Layering Is Necessary in Development
In everyday software development, tasks vary significantly in nature. Some require understanding business constraints, decomposing requirements, and assessing risks—such as designing data models, clarifying interface boundaries, or tracing subtle cross-module defects. Other tasks have well-defined boundaries and outputs that can be directly verified—for example, adding comments in bulk according to established conventions, writing unit tests for existing functions, converting one configuration format to another, or renaming fields item by item against a checklist.
These two categories place different demands on language models. The former relies on reasoning depth and judgment; the latter emphasizes execution accuracy, fast response times, and strict adherence to the requested scope. Using a single model for all tasks typically leads to two problems. First, simple tasks take too long, and developers lose context while waiting. Second, the model proactively introduces unrequested validation logic, permission checks, or explanatory text during execution, causing scope creep and increasing review overhead.
For this reason, teams need to assign models by role, making the choice of which model to use an engineering decision that can be evaluated and revisited—rather than a matter of intuition.
2. A Role-Based Framework for Model Assignment
Three questions help determine which type of model a task should be assigned to:
- Is the requirement clear? If the goal, input, and output format are all well-defined, the task is suitable for an executor model.
- Is the output verifiable? Can the result be quickly confirmed through compilation, tests, or diff review? Highly verifiable tasks are well suited for executor models.
- What is the cost of failure? Tasks involving data migration, permission changes, or production configuration must go through human review regardless of which model is selected.
| Task Type | Recommended Role | Typical Example |
|---|---|---|
| Requirement analysis, solution design | Planner model | Designing a cache invalidation strategy |
| Cross-module issue diagnosis | Planner model | Analyzing the call chain of a sporadic timeout |
| Bulk modifications, boilerplate code | Executor model | Unifying the API response structure |
| Unit test completion | Executor model | Adding boundary test cases for existing utility functions |
| Documentation and comments | Executor model | Generating API documentation from a template |
The core principle of this framework is to let planner models handle the thinking and executor models handle the execution.
3. Building a Reproducible Evaluation Set
Model selection decisions should not rely on a single interaction. A successful conversation may be a coincidence, and a failure may stem from a poorly written prompt. Teams should establish a fixed evaluation set and re-run it whenever model versions change.
Consider the following guidelines for constructing the evaluation set:
- Group tasks by category, such as code generation, code modification, test writing, documentation generation, and defect localization, with several real samples per category.
- Attach acceptance criteria to each sample, such as “tests must pass” or “modified files must be limited to the specified directory.”
- Use samples taken from real repository history where possible, avoiding overly idealized, hand-crafted problems.
Useful evaluation metrics include:
- First-try pass rate: The proportion of outputs that pass acceptance checks without human follow-up.
- Out-of-scope modification rate: The proportion of tasks where files outside the requested scope were modified.
- Extra constraint rate: The proportion of outputs containing validations, restrictions, or comments that were not requested.
- Average latency and cost: Time from request submission to usable output, along with the associated API cost.
The following pseudocode illustrates how to collect these metrics. The specific model invocation method depends on the team’s actual environment:
for case in evaluation_set:result = run_model(model_id, case.prompt, case.context)passed = run_acceptance_checks(case, result)changed_files = collect_changed_files(result)out_of_scope = [f for f in changed_files if not case.in_scope(f)]record(case_id=case.id,passed_first_try=passed,out_of_scope=len(out_of_scope) > 0,latency_ms=result.latency_ms,cost=result.cost,)report = aggregate_by_category(records)
Whenever possible, use blind evaluation—reviewers should not know which model produced a given result—to reduce the influence of subjective bias.
4. Common Failure Modes and Mitigations
In executor-type tasks, the following issues tend to occur frequently.
Over-engineering. When modifying a simple function, the model proactively adds parameter validation, exception wrapping, or permission checks, making the diff far larger than necessary. Mitigation: explicitly state in the task description that only the specified changes should be made and no unlisted validations or dependencies should be added. Track the extra constraint rate in the evaluation set.
Slow responses. For simple, well-defined tasks, extended reasoning only reduces efficiency. Mitigation: tier tasks by difficulty. Route simple tasks directly to faster executor models and reserve planner models for complex ones.
Instruction drift. The task requires changing only one module, but the model also adjusts configuration files or shared utilities. Mitigation: enforce a change-scope check in the workflow. Any modification outside the approved list should be automatically blocked and require human confirmation.
Capability regression. A new model version improves on some categories but degrades on others. Mitigation: maintain a fixed regression set and analyze trends per category rather than only looking at the overall score.
5. Engineering Implementation: Routing and Fallback
The routing strategy can be expressed as a simple function. The pseudocode below shows how to select a model based on task attributes and fall back to a planner model when validation fails:
def route_task(task):if task.requirement_is_clear and task.output_is_verifiable and task.risk_level == "low":return "executor"return "planner"def run_with_fallback(task):model = route_task(task)result = call_model(model, task)if not passes_checks(result):result = call_model("planner", task, hint=result.failure_reason)return result
Three quality gates should be established in the workflow:
- Automated tests and static checks: Any model output must pass these before being considered.
- Change-scope verification: Modifications outside the approved list are blocked automatically.
- Human review: Changes involving security, data, or production configuration must be confirmed by a person.
At the same time, teams should track latency and cost per task category to confirm that the routing strategy genuinely reduces end-to-end development time. Lowering the unit price of a single call does not necessarily lower overall cost, because rework and review consume engineering hours as well.
6. Iteration and Team Collaboration
Model capabilities change with new versions, and selection decisions must be updated accordingly. It is recommended to:
- Re-run the fixed evaluation set whenever a model version changes.
- Review category-level trends and adjust routing rules based on the results.
- Document the rationale behind each selection decision so the team can revisit and revise it as conditions evolve.
