Evaluating and Selecting Large Language Models for Coding and Writing

    A practical framework for evaluating LLMs across code generation, long-context understanding, writing quality, multimodal input, consistency, and cost. This guide explains how to build reproducible test sets, standardize evaluation conditions, combine automated scoring with human review, track model versions, and connect evaluation results to real business outcomes.

    1. Why Systematic Evaluation Matters

    Large language model performance can vary significantly depending on the task, prompt design, model version, and inference parameters. A single successful or unsuccessful interaction says little about whether a model is reliable overall.

    Teams that select models based only on intuition commonly encounter three problems:

    1. The sample size is too small, so accidental results are mistaken for general patterns.
    2. Evaluation conditions are inconsistent, making results difficult to compare.
    3. The team focuses on a single metric, such as price or a general benchmark score, while overlooking the capabilities required by the actual business scenario.

    A sound evaluation process should therefore start with business scenarios. Define the tasks first, then establish the metrics, standardize the workflow, and run the evaluation repeatedly.

    2. Breaking Down the Evaluation Dimensions

    2.1 Code Understanding and Generation

    Coding tasks usually need to test three capabilities at the same time:

    • Whether the generated result is functionally correct
    • Whether it follows the conventions already used in the project
    • Whether the model can explain its design choices

    The following submetrics can be used:

    • Functional accuracy: Whether the generated code passes predefined unit tests.
    • Context utilization: Whether the model correctly references functions, types, and configuration after receiving excerpts from multiple files.
    • Quality feedback: Whether it identifies potential performance bottlenecks, edge cases, and security risks.

    Functional accuracy is the easiest metric to quantify and should usually be the primary measure. Quality feedback requires human review to prevent the model from inventing problems merely to appear knowledgeable.

    2.2 Long-Text and Intent Understanding

    When the input contains lengthy requirements documents, logs, or meeting notes, the model must identify the key constraints.

    One evaluation method is to embed several important conditions in the text and measure whether the model misses them. For example, a 20-page requirements document might include one restriction that conflicts with information in another section. The evaluation can then test whether the model proactively identifies the contradiction.

    2.3 Writing Quality and Style Control

    The main challenges in writing tasks are maintaining a consistent style and preserving factual accuracy. Consider splitting the evaluation into three metrics:

    • Whether the required length and structure are followed
    • Whether terminology is accurate
    • Whether the tone matches the target audience

    Style is inherently subjective. A double-blind scoring process can help: two reviewers score each output independently, and they discuss cases with significant disagreement.

    2.4 Multimodal Input

    If a business process involves charts, screenshots, or scanned documents, image understanding should be tested separately.

    Prepare a set of samples with ground-truth answers, such as table value extraction and flowchart node identification, and calculate accuracy at the field level.

    2.5 Stability and Consistency

    The same prompt may produce different outputs at different times or across different batches. Stability can be measured using the standard deviation of scores from multiple runs of the same task. A smaller standard deviation indicates more predictable output, which is generally more suitable for an automated workflow.

    2.6 Cost and Invocation Strategy

    Cost depends on unit pricing, input and output length, and the number of retries. Evaluation should calculate the average cost per successfully completed task, rather than considering only the price of a single call.

    This makes it possible to compare accuracy and cost on the same basis.

    3. Building a Reproducible Evaluation Workflow

    An evaluation workflow can be divided into four steps.

    Step 1: Build the task set. Prepare 20 to 100 samples for each task category, covering both common scenarios and edge cases. Samples should come from real business requirements whenever possible, and each should include a reference answer or a defined scoring rubric.

    Step 2: Standardize the evaluation conditions. Fix the prompt template, system instructions, maximum output length, sampling parameters, and other relevant settings. If any of these conditions change, the results should not be compared directly.

    Step 3: Combine automated scoring with human review. Use test cases for automatic scoring wherever possible. Subjective tasks should be reviewed manually, with a sample review rate of approximately 10% to 20%.

    Step 4: Record the model version and evaluation date. Model providers may update the underlying version of a service. Each evaluation should therefore record the invocation time, model identifier, and parameters for later traceability.

    The following generic evaluation loop repeatedly invokes a model for the same task and measures the distribution of results:

    1. def evaluate(model, tasks, scorer, runs=3):
    2. results = []
    3. for task in tasks:
    4. scores = []
    5. for _ in range(runs):
    6. output = model.generate(
    7. prompt=task["prompt"],
    8. temperature=0,
    9. max_tokens=task.get("max_tokens", 2048),
    10. )
    11. scores.append(scorer(task, output))
    12. results.append({
    13. "task_id": task["id"],
    14. "mean": sum(scores) / len(scores),
    15. "spread": max(scores) - min(scores),
    16. })
    17. return results

    Here, spread represents the difference between multiple outputs for the same task. If a category continues to show a large spread, first check whether the prompt is ambiguous before considering a different model.

    4. Common Evaluation Mistakes

    Mistake 1: Treating a single experience as a statistical conclusion. One or two successful examples do not demonstrate overall capability. The task-set pass rate should be the basis for conclusions.

    Mistake 2: Ignoring model-version drift. The underlying implementation may change over time even when the model name remains the same. If output quality declines noticeably, check the invocation records before drawing conclusions.

    Mistake 3: Looking only at price or benchmark rankings. Public benchmarks usually use general-purpose tasks and may not reflect a specific business scenario. A lower-priced model may require more retries, resulting in a higher total cost.

    Mistake 4: Overlooking data compliance. Evaluation samples containing customer data or internal code should be anonymized first. Also confirm that the service’s data-use terms meet the organization’s security requirements.

    5. Practical Recommendations

    First, make evaluation a recurring process rather than a one-time project. Run it quarterly or after every major model-version change to build trend data.

    Second, select models by scenario instead of searching for one universally optimal model. Code generation, document summarization, and customer support require different capabilities, so separate solutions may be appropriate.

    Third, connect evaluation results to business metrics, such as code review approval rates or first-contact ticket resolution rates. Metrics are worth tracking over time only when they affect real operational efficiency.

    Fourth, if the team uses a cloud platform to build the evaluation environment—for example, container and logging capabilities provided by Baidu AI Cloud—task scheduling, result storage, and alerting can be managed within the same infrastructure, making audits and retrospective analysis easier.

    Ultimately, model selection is an ongoing engineering process. With a clearly defined task set, standardized evaluation conditions, and traceable records, teams can make stable and explainable decisions as model capabilities and costs change.