LLM Selection in Practice: Coding Ability, Tool Calling, and Cost Evaluation

    Public benchmark scores can help narrow the candidate list, but they rarely show how a model will perform in a real project. This article presents a practical LLM selection process built around task fit, tool-calling ability, unit cost, stability, and integration effort. It also explains how to create a small in-house evaluation set, calculate cost per successful task, and test stability with retries.

    1. Why You Cannot Rely on Leaderboard Scores Alone

    Public benchmarks provide a rough reference, but they can hardly answer the question, “Will this model work well in my project?” There are three main reasons.

    First, benchmark tasks differ from real work. Benchmark problems are usually independent, clearly bounded small questions, while day-to-day development often involves multi-file changes, ambiguous requirements, and legacy code constraints.

    Second, evaluation conditions affect results. Prompt templates, sampling temperature, context length, and whether multiple attempts are allowed can all change scores. The same model may rank very differently under different settings.

    Third, average scores can hide long-tail problems. A model may have a high overall score but frequently fail on a particular language or task type, which can make it a worse choice for your team.

    Therefore, public leaderboards are useful for narrowing the candidate list, but the final decision should rely on your own data.

    2. Define Evaluation Dimensions First

    Before selecting a model, break requirements into measurable dimensions. The following five cover most development scenarios.

    1. Task fit: Code generation, defect localization, refactoring, test-case writing, and documentation writing have different success criteria and need to be measured separately.
    2. Tool-calling ability: Whether the model can select the correct function, generate calls that match parameter definitions, and maintain context consistency across multi-step calls.
    3. Unit cost: Token-based services usually have separate input and output prices, and output is often priced higher. Long contexts and long reasoning content both increase cost; refer to the provider’s published pricing rules.
    4. Stability: Focus on latency distribution rather than averages, and track timeout rate, rate-limit frequency, and whether the output format is always parseable.
    5. Integration cost: Whether the API protocol is compatible with common SDKs, whether error codes are clear, and whether quota and permission management meet team needs.

    3. Build Your Own Evaluation Set

    The evaluation set does not need to be large, but it must come from real scenarios. Suggested steps:

    1. Collect 30 to 100 tasks from recent work, covering the most common types.
    2. For each task, specify the input, context, and acceptance criteria. The most reliable acceptance method is running the project’s own tests.
    3. Run model output in an isolated environment, and record pass rate, scope of changes, and manual correction time. Reset the workspace before each case to avoid cross-contamination.
    4. Break down results by layer and observe differences across languages and modules.

    In the example code below, the model call is a placeholder function; replace it with the actual client.

    1. import subprocess
    2. from dataclasses import dataclass
    3. @dataclass
    4. class Case:
    5. name: str
    6. prompt: str
    7. test_cmd: list[str] # Command to run the task's tests, provided by the config file
    8. def call_model(prompt: str) -> str:
    9. """Placeholder function: replace with the actual model call and return the generated code patch."""
    10. raise NotImplementedError
    11. def reset_workspace(workdir: str) -> None:
    12. ... # Restore to a clean version, e.g., re-check out the baseline commit
    13. def apply_patch(patch: str, workdir: str) -> None:
    14. ... # Only allow modifications to files on the whitelist
    15. def run_case(case: Case, workdir: str) -> bool:
    16. reset_workspace(workdir)
    17. patch = call_model(case.prompt)
    18. apply_patch(patch, workdir)
    19. result = subprocess.run(case.test_cmd, cwd=workdir,
    20. capture_output=True, timeout=120)
    21. return result.returncode == 0
    22. def evaluate(cases: list[Case], workdir: str) -> float:
    23. passed = sum(run_case(c, workdir) for c in cases)
    24. return passed / len(cases)

    Note that model-generated code should not be run directly on the host; execute it in a container or sandbox.

    4. Convert Cost to “Cost per Successful Task”

    The price of a single call is easy to compare, but the real cost depends on how much each successful result costs. Failed tasks require retries or manual correction, and that overhead must be included.

    The basic formulas are:

    Cost per call = input tokens / 1,000,000 × input price + output tokens / 1,000,000 × output price

    Cost per successful task = total evaluation-set cost / number of passed tasks

    1. def cost_per_success(input_tokens: int, output_tokens: int,
    2. in_price: float, out_price: float, passed: int) -> float:
    3. # Price unit: per million tokens
    4. total = (input_tokens / 1_000_000) * in_price \
    5. + (output_tokens / 1_000_000) * out_price
    6. return total / passed if passed else float("inf")

    If two models have the same unit price but their pass rates differ by a factor of two, their actual cost per successful task will also differ by a factor of two. Therefore, compare both unit price and pass rate. Manual correction time should also be converted into labor hours and included in the total cost.

    5. Stability Testing and Retry Strategy

    Stability needs repeated measurement. Running the same task multiple times and checking whether results are consistent is more informative than a single run.

    It is advisable to continuously record the following metrics:

    • P50, P95, and P99 latency percentiles
    • Distribution of timeouts and error codes
    • Output-format validation failure rate
    • Consistency of results across multiple runs with the same input

    For transient errors such as rate limiting and network jitter, a common approach is exponential backoff with retries and an attempt limit.

    1. import random
    2. import time
    3. def with_retry(fn, max_attempts: int = 4, base_delay: float = 1.0):
    4. for attempt in range(max_attempts):
    5. try:
    6. return fn()
    7. except TimeoutError: # Replace with the actual retryable exception thrown by the client
    8. if attempt == max_attempts - 1:
    9. raise
    10. time.sleep(base_delay * (2 ** attempt) + random.uniform(0, 0.1))