A Practical Guide to Large Language Model Selection and Task Planning for Coding Tasks

    This article provides a practical guide for selecting large language models and formulating task plans in software development. It explores why coding tasks require dedicated planning, how to decompose requirements into verifiable steps, the four dimensions for model selection, how to build internal evaluation sets using real tasks, and strategies for risk control and manual review. Developers and engineering managers will learn how to optimize AI-assisted coding by structuring tasks, defining clear completion criteria, and matching the right model to the right job.

    1. Why Coding Tasks Require Separate Planning

    In software development, large models are commonly used for code generation, bug localization, unit test writing, code review, and documentation completion. These tasks demand a high degree of output precision. A seemingly reasonable piece of code, if its interface signature is inconsistent with existing modules or ignores boundary conditions, will expose problems during the integration phase, resulting in even higher repair costs.

    Therefore, coding tasks require a plan before discussing the models. The plan determines how tasks are segmented, what each step outputs, how they are verified, and which type of model should handle each step. Without a plan, teams often feed an entire large requirement to the model at once, resulting in a massive block of changes that is difficult to review, hard to debug, and tough to roll back.

    1.1 Three Common Failures

    • Scope creep: A single request modifies too many files with ambiguous change boundaries, making it impossible for reviewers to determine which changes are necessary.
    • Lack of verification: The generated results have no corresponding tests, relying solely on manual reading to judge correctness. The review cost increases rapidly with the amount of code.
    • Context disconnect: Project conventions, data structures, or historical decisions that the task relies on are not provided to the model, causing the output to conflict with existing code styles and architecture.

    These three types of problems are related to the model’s own capabilities, but they more often stem from how the task is organized. The same model usually performs significantly better on tasks that are clearly decomposed and have explicit constraints.

    2. Breaking Down Requirements into Verifiable Steps

    Effective decomposition follows two principles: each step must have clear inputs and outputs, and each step must be verifiable automatically or manually.

    Taking “adding a time-range export feature to an order module” as an example, it can be broken down into the following steps:

    1. Define interfaces: Determine request parameters, return formats, and error codes.
    2. Data query: Implement a query function that filters by time range, and evaluate whether a new index is needed.
    3. Export logic: Convert query results into the target format, handling empty results and data volume limits.
    4. Test cases: Cover normal paths, boundary times, invalid parameters, and large data volume scenarios.
    5. Integration verification: Run the end-to-end flow in the test environment, checking logs and monitoring metrics.

    After each step is completed, a check is performed before moving to the next step. Even if an output in a certain step is incorrect, the impact of the problem is confined to that step and will not spread to the entire feature.

    2.1 Write Clear Completion Criteria for Each Step

    Completion criteria should be executable judgments rather than subjective descriptions like “good code quality.” For example, “the newly added function passes all unit tests and does not modify public interfaces” is a verifiable standard. The more specific the completion criteria, the clearer the acceptable range of the model’s output, and the more efficient the manual review process.

    3. Four Dimensions of Model Selection

    When selecting a model, it is not necessary to rely solely on overall rankings. A more practical approach is to match models to specific tasks based on task characteristics. The following four dimensions can form an evaluation framework.

    3.1 Capability Matching

    Different tasks have vastly different capability requirements. Boilerplate code generation and simple completions are sensitive to response speed, while complex refactoring and cross-module reasoning rely more on reasoning depth. Teams can categorize tasks into three tiers: simple, medium, and complex, assigning candidate models to each tier to avoid using the same model for all tasks.

    3.2 Context Length and Cost

    Large code bases often require the model to read multiple files. The longer the context, the higher the input cost and response time usually are. In practice, you can first retrieve files relevant to the task and only provide function signatures and dependency summaries to control the input size.

    Cost evaluation should be calculated based on the “average completion cost per task” rather than per single API call. The time spent on failed retries and manual corrections is also part of the cost; ignoring them will underestimate the true expenses.

    3.3 Response Latency

    In interactive coding scenarios, latency directly affects a developer’s focus. For background batch tasks, such as generating tests overnight or batch-adding comments, latency has a smaller impact, allowing you to choose more cost-effective models.

    Teams should separately record the latency distribution for interactive and batch processing scenarios, paying attention to long-tail values beyond the median. Long-tail latency is often the real reason users experience “lag.”

    3.4 Engineering Integration

    Whether a model can be smoothly integrated into an existing pipeline is equally critical. The following issues need to be considered:

    • Is the output format stable, and can it be returned in an agreed-upon structure?
    • Are error messages parseable for automatic program retries?
    • How are rate limits handled, and do batch tasks require queuing and backoff mechanisms?

    When the output format is unstable, downstream parsing code will frequently throw errors, and actual efficiency will drop significantly. Such issues are not easily exposed during the demo phase but will cluster after going live.

    4. Building an Evaluation Set with Real Tasks

    General leaderboards can provide a reference, but they measure general capabilities that may not cover a team’s own codebase, coding standards, and business scenarios. A more reliable method is to build an internal evaluation set.

    The steps to build an evaluation set are as follows:

    1. Select 50 to 100 typical tasks from real tickets, defect records, and code review records from the past six months.
    2. Save the input context, expected behavior, and executable test scripts for each task.
    3. Run the same batch of tasks on candidate models, recording the pass rate, lines of code changed, manual correction time, and cost.
    4. Aggregate results by task category to determine the default and backup models for each task type.

    Below is a simplified evaluation script framework for calculating pass rate and average latency. The model invocation part is encapsulated as call_model, and its specific implementation depends on the service interface used by your team.

    1. import subprocess
    2. import time
    3. from dataclasses import dataclass, field
    4. @dataclass
    5. class EvalCase:
    6. case_id: str
    7. prompt: str
    8. test_cmd: list[str] # e.g., ["pytest", "tests/test_export.py"]
    9. @dataclass
    10. class EvalResult:
    11. case_id: str
    12. passed: bool
    13. latency_s: float
    14. notes: list[str] = field(default_factory=list)
    15. def run_case(case: EvalCase, call_model, apply_patch) -> EvalResult:
    16. start = time.perf_counter()
    17. patch = call_model(case.prompt) # Returns patch text in a unified format
    18. apply_patch(patch) # Applies the patch to the workspace
    19. proc = subprocess.run(case.test_cmd, capture_output=True, text=True)
    20. latency = time.perf_counter() - start
    21. notes = [] if proc.returncode == 0 else [proc.stdout[-500:]]
    22. return EvalResult(case.case_id, proc.returncode == 0, latency, notes)
    23. def summarize(results: list[EvalResult]) -> dict:
    24. total = len(results)
    25. passed = sum(r.passed for r in results)
    26. avg = sum(r.latency_s for r in results) / total if total else 0.0
    27. return {
    28. "pass_rate": passed / total if total else 0.0,
    29. "avg_latency_s": round(avg, 2),
    30. }

    When executing external test commands, parameters should be passed as a list to avoid command injection risks associated with string concatenation. Patch content originates from the model output and should be treated as untrusted data; verify that its modification paths are within allowed bounds before applying.

    5. Structured Templates for Phased Coding Plans

    The plan itself can also be structured to facilitate tracking and reuse. Below is an example of a data structure for a task plan:

    1. from dataclasses import dataclass, field
    2. from typing import Literal
    3. @dataclass
    4. class Step:
    5. name: str
    6. goal: str
    7. inputs: list[str]
    8. outputs: list[str]
    9. done_when: str
    10. model_tier: Literal["simple", "medium", "complex"]
    11. @dataclass
    12. class TaskPlan:
    13. title: str
    14. constraints: list[str]
    15. steps: list[Step] = field(default_factory=list)

    When using this template, note three key points:

    • constraints records boundaries that cannot be altered, such as public interfaces, database structures, and compatibility requirements. These constraints should be attached every time the model is called.
    • done_when must be verifiable, ideally corresponding to an automated test.
    • model_tier is used to assign simple steps to lower-cost models and complex reasoning to more capable models.

    6. Risk Control and Manual Review

    The higher the degree of automation, the more explicit the review mechanism needs to be. The following practices are recommended:

    • Small-step commits: Each step corresponds to an independent commit, allowing precise rollbacks when issues arise.
    • Scope checks: Limit the number of files and lines changed in a single modification; manual confirmation is required when thresholds are exceeded.
    • Security review: Code involving authentication, encryption, input parsing, and external calls must undergo manual review.