How to Evaluate and Integrate a New LLM

    Evaluate new large language models against your own workloads before switching. This guide covers benchmark interpretation, cost per successful task, internal evaluation datasets, staged rollouts, rollback planning, and ongoing production monitoring.

    1. Define the Evaluation Questions First

    When a new model launches, the available information typically includes benchmark scores, pricing, and recommended use cases. These details indicate its general capabilities, but they do not establish how well it will perform in your application.

    An evaluation should answer three questions:

    • How well does the new model perform on your tasks?
    • What is the total cost of completing a task?
    • Can the risks of switching models be controlled?

    Answering only the first question is not enough. A higher-scoring model may deliver less overall value if it doubles the cost per attempt or produces inconsistent output formats that require substantial rework. Evaluate quality, cost, and reliability together.

    2. Interpret Benchmark Scores Carefully

    Benchmark results depend on the test dataset, scoring rules, and execution environment. When reviewing them, focus on the following:

    • Task sources: Do the tests reflect real engineering work, such as code changes, bug fixes, and changes across multiple files, or are they primarily academic exercises?
    • Pass-rate definition: Does the score measure success on a single attempt or the best result from multiple samples? These are substantially different measures.
    • Tools and context: Could the model use tools or search a code repository? What context length was used?
    • Model version and test date: Models with the same name may have different snapshots. Results collected at different times are not necessarily comparable.

    A difference of a few percentage points on the same benchmark is not, by itself, enough to establish a meaningful difference in production. Consider sample size and result variability. With a small dataset, random variation across runs can exceed the reported score gap.

    3. Calculate Cost per Task

    Cost comparisons should go beyond the price per million tokens. The full cost of a task typically includes:

    • Input tokens, including system prompts, conversation history, and retrieved content.
    • Output tokens.
    • Additional reasoning tokens, if the model uses them and they are billable.
    • Repeated calls after failed attempts.
    • Time spent on human review and rework.

    A more useful comparison metric is average cost per successful task. Assuming each attempt has a fixed cost and attempts are independent, an 80% success rate means that each successful task costs an average of 1.25 attempts.

    The following function calculates this estimate:

    1. def cost_per_success(
    2. input_tokens: int,
    3. output_tokens: int,
    4. price_in: float,
    5. price_out: float,
    6. success_rate: float,
    7. ) -> float:
    8. """
    9. Estimate the average cost per successful task.
    10. price_in and price_out are per-token prices in the same currency
    11. as the returned value.
    12. success_rate is the success rate per attempt, in the range (0, 1].
    13. """
    14. if not 0 < success_rate <= 1:
    15. raise ValueError("success_rate must be in the range (0, 1]")
    16. per_attempt = input_tokens * price_in + output_tokens * price_out
    17. return per_attempt / success_rate
    18. # These values are illustrative. Check the provider's published pricing.
    19. cost_a = cost_per_success(3000, 800, price_in=2e-6, price_out=8e-6, success_rate=0.92)
    20. cost_b = cost_per_success(3000, 1200, price_in=1e-6, price_out=4e-6, success_rate=0.78)
    21. print(f"Model A cost per successful task: {cost_a:.5f}")
    22. print(f"Model B cost per successful task: {cost_b:.5f}")

    Lower token prices do not necessarily translate into lower task costs. A lower success rate increases the cost per successful task, while longer outputs increase total spending. Before making a cost decision, measure success rates and average token usage using real workload samples.

    4. Build an Internal Evaluation Dataset

    General benchmarks are useful reference points, but the final decision should depend on your own evaluation dataset. Consider the following when building it:

    • Sample sources: Draw from historical support tickets, actual requirements, and production logs. Cover frequent tasks as well as edge cases and inputs that commonly cause errors.
    • Sample size: Aim for at least 100 examples overall, with additional coverage for critical task categories to reduce the impact of random variation.
    • Scoring: Automate checks wherever possible, using methods such as JSON field validation, unit tests, and regular expressions. Use human review for results that cannot be assessed automatically.
    • Blind review: Hide model identities from reviewers to reduce subjective preferences.

    The following is a simplified evaluation framework. Your team should implement the model-call wrapper with consistent timeout, retry, and logging rules.

    1. from typing import Callable
    2. def run_eval(
    3. cases: list[dict],
    4. model_call: Callable[[str], str],
    5. judge: Callable[[dict, str], bool],
    6. ) -> dict:
    7. """
    8. Run a model against a set of cases and calculate the pass rate.
    9. cases: Each case includes id and prompt fields, plus any expected
    10. information needed for scoring.
    11. model_call: Takes a prompt and returns the model's output text.
    12. judge: Takes a case and the model output, and returns whether it passes.
    13. """
    14. details = []
    15. for case in cases:
    16. try:
    17. output = model_call(case["prompt"])
    18. passed = judge(case, output)
    19. except Exception:
    20. # Count failed calls as failures; retain error details in
    21. # the model-call wrapper's logs for troubleshooting.
    22. output, passed = "", False
    23. details.append({"id": case["id"], "passed": passed, "output": output})
    24. pass_count = sum(1 for d in details if d["passed"])
    25. return {
    26. "pass_rate": pass_count / len(details),
    27. "details": details,
    28. }

    When comparing models, keep the samples, prompts, sampling parameters such as temperature, and scoring criteria identical. Otherwise, you cannot attribute the observed differences to the models themselves.

    5. Roll Out Gradually and Prepare for Fast Rollback

    Passing an evaluation does not justify switching all production traffic immediately. A staged rollout is safer:

    1. Shadow testing: Run the new and existing models on the same requests. Record the new model’s results without returning them to users.
    2. Limited rollout: Route a small share of live traffic, such as 1% to 5%, to the new model.
    3. Metric gates: Increase traffic only after success rate, latency, cost per task, and user complaint rate meet predefined thresholds.
    4. Fast rollback: Use a configuration switch or routing rules that can move traffic back to the existing model within minutes.

    Define these thresholds during evaluation, not after deployment. Setting them in advance helps prevent reactive decisions when metrics fluctuate.

    6. Monitor Continuously After Deployment

    Providers may update model versions, so evaluation should continue after deployment. At a minimum, monitor:

    • Success rates by task category, rather than only the overall average.
    • P95 and P99 latency, so averages do not hide slow requests.
    • Changes in input and output token distributions.
    • Output-format error rates, refusal rates, and the proportion of outputs that violate defined content boundaries.
    • Regular samples for human review, with the model version and sampling time recorded.

    If any metric persistently deviates from its baseline, trigger an alert and rerun the evaluation dataset. Logs should retain the model version, prompt version, and parameter configuration so that problems can be traced to their source.

    7. Evaluation and Rollout Checklist

    • Define task categories, success criteria, and unacceptable errors.
    • Build an internal evaluation dataset with at least 100 examples, including edge cases.
    • Calculate cost per successful task instead of comparing token prices alone.
    • Compare models using identical samples and parameters.
    • Set rollout thresholds in advance and prepare a rollback switch that takes effect within minutes.
    • Record model versions, prompt versions, and evaluation dates to support reproducibility.