LLM Selection and Evaluation: Building a Multidimensional Framework

    A practical framework for comparing large language models using reusable test sets, weighted scoring, and measurements of latency and cost. Learn how to assess context handling, output completeness, false refusals, and readability—and avoid common mistakes when interpreting evaluation results.

    Why a Single Trial Is Not Enough

    Large language models change frequently, and a subjective impression from one trial rarely reflects production performance. An answer may read more smoothly simply because the question happens to match a model’s strengths. Engineering teams need reproducible, measurable evaluations that turn “feels better” into comparable metrics.

    This article does not benchmark a particular product. Instead, it outlines a general evaluation workflow: define the dimensions, build a test set, design scoring and measurement methods, and interpret the results to support model selection.

    1. Define the Evaluation Dimensions

    Model selection typically involves six areas.

    Context Handling

    Context handling covers both the input length a model accepts and its ability to locate relevant information in long documents. The advertised context limit is only a capacity ceiling. Actual performance depends on where information appears and how much distracting content surrounds it.

    Place key information at the beginning, middle, and end of test documents, then measure recall for each position. This helps identify whether the model struggles disproportionately with information in the middle.

    Output Capability

    Evaluate the maximum output length per response, along with discontinuities, repetition, and omissions in longer outputs. This is especially important when generating long reports or complete source files.

    Check whether the response reaches a complete ending rather than being cut off midway.

    API Cost

    Most services charge by input and output token counts, often with discounts for cached input. Cost estimates should reflect the workload’s typical input-to-output ratio.

    For example, if the application processes long documents and produces short summaries, input pricing will have a much greater effect on total cost than output pricing.

    Response Latency

    Latency includes time to first token (TTFT) and overall generation speed. Interactive applications, such as chat assistants and code completion, place particular emphasis on TTFT: the wait for the first visible response strongly affects how responsive the application feels.

    Batch workloads place greater emphasis on throughput—the number of tasks completed per unit of time.

    Safety False-Refusal Rate

    The false-refusal rate measures how often a model incorrectly refuses legitimate requests. Safety safeguards are necessary, but overly restrictive behavior can reduce usability. A model might, for example, reject a legitimate biology assignment or security research question.

    Track this metric separately from the rate at which genuinely risky requests are blocked.

    Readability

    Assess whether answers are clear, explain terminology adequately, and use an easy-to-follow structure. Readability is often overlooked, even though it directly affects the effort required to understand and edit a response.

    Use human reviewers or a structured rubric rather than relying on general impressions.

    2. Build a Reusable Test Set

    The test set is the foundation of the evaluation. Organize cases by business scenario, and include at least three types of examples in each scenario:

    • Common requests
    • Edge cases
    • Historical failures

    Sources can include anonymized support tickets, real user questions, and manually constructed extreme cases.

    The initial test set does not need to be large, but its distribution should resemble real traffic. Each case should record the input, expected key points, category, and whether the request should be refused. These fields support reproducibility and traceability.

    A simplified data structure might look like this:

    1. from dataclasses import dataclass, field
    2. @dataclass
    3. class EvalCase:
    4. case_id: str
    5. category: str # Scenario, such as code generation or document summarization
    6. prompt: str # Input text
    7. must_include: list[str] = field(default_factory=list) # Required key points
    8. should_refuse: bool = False # Whether the request should be refused

    Wrap model calls in a common interface to hide differences between services. The evaluation code can then focus on inputs and outputs:

    1. REFUSAL_MARKERS = [
    2. "I cannot provide",
    3. "I cannot assist",
    4. "I cannot fulfill this request",
    5. ]
    6. def is_refusal(text: str) -> bool:
    7. # This keyword-based heuristic is only for initial screening.
    8. # Formal evaluation should use human labels or an evaluator model.
    9. return any(marker in text for marker in REFUSAL_MARKERS)
    10. def run_eval(cases, call_model):
    11. results = []
    12. for case in cases:
    13. output = call_model(case.prompt)
    14. keyword_hit = all(k in output for k in case.must_include)
    15. refused = is_refusal(output)
    16. results.append({
    17. "id": case.case_id,
    18. "category": case.category,
    19. "keyword_hit": keyword_hit,
    20. "refused": refused,
    21. # False refusal: a request that should be answered is refused.
    22. "false_refusal": (not case.should_refuse) and refused,
    23. })
    24. return results

    The team implements call_model to connect to the selected model service and return its text response. Separating invocation logic from evaluation logic allows the same test set to compare different models and be rerun after version updates.

    3. Design Scoring and Weighting

    Keyword matching can check whether an answer includes required points, but it cannot establish correctness or overall quality. A practical scoring system therefore combines automated metrics with human assessment.

    Automated metrics support inexpensive screening at scale. Human reviewers are better suited to judging subtle quality differences.

    Normalize dimension scores to a range of 0 to 1, then calculate a weighted sum based on business priorities. There is no universal set of weights. For medical or legal consultation scenarios, correctness should carry substantially more weight than cost. For internal batch document-processing tasks, cost and latency may deserve greater emphasis.

    1. WEIGHTS = {
    2. "correctness": 0.35, # Answer correctness
    3. "latency": 0.15, # Latency
    4. "cost": 0.20, # Cost
    5. "safety_false_refusal": 0.15, # False-refusal control
    6. "readability": 0.15, # Clarity and presentation
    7. }
    8. def weighted_score(scores: dict[str, float]) -> float:
    9. assert abs(sum(WEIGHTS.values()) - 1.0) < 1e-9, "Weights must sum to 1"
    10. return sum(WEIGHTS[k] * scores[k] for k in WEIGHTS)

    Once established, weights should remain as stable as possible. Changing them for every evaluation undermines comparability across models. If business objectives genuinely change, record the reason for the adjustment and its date.

    4. Measure Latency and Cost

    Use streaming responses to measure latency, recording three timestamps:

    • When the request is sent
    • When the first response chunk arrives
    • When the response finishes

    Total duration alone cannot distinguish the initial wait from subsequent generation speed, even though they affect user experience differently.

    1. import time
    2. def measure_latency(stream_fn, prompt):
    3. start = time.perf_counter()
    4. first_chunk_at = None
    5. chunks = []
    6. for chunk in stream_fn(prompt):
    7. if first_chunk_at is None:
    8. first_chunk_at = time.perf_counter()
    9. chunks.append(chunk)
    10. end = time.perf_counter()
    11. return {
    12. "ttft_ms": (first_chunk_at - start) * 1000 if first_chunk_at else None,
    13. "total_ms": (end - start) * 1000,
    14. "output_chars": sum(len(c) for c in chunks),
    15. }

    Base cost estimates on the provider’s current published prices. Avoid hard-coding prices in application logic: service pricing changes, so prices should be read from configuration and updated when needed.

    1. def estimate_cost(input_tokens: int, output_tokens: int,
    2. price_in_per_m: float, price_out_per_m: float) -> float:
    3. """
    4. price_in_per_m and price_out_per_m are prices per million tokens.
    5. The caller supplies prices and currency based on the current price list.
    6. """
    7. return (input_tokens / 1_000_000) * price_in_per_m \
    8. + (output_tokens / 1_000_000) * price_out_per_m

    Cost estimates should also distinguish cached from uncached tokens. When the same prompt content appears across repeated requests, caching discounts can materially change the total cost. Ignoring them can produce misleading estimates.

    5. Avoid Common Interpretation Mistakes

    Evaluation results are easy to misread. Pay particular attention to these issues:

    • Random variation from small samples. Results can fluctuate substantially when the test set is small. Run the same cases multiple times, calculate the mean, and record the standard deviation to assess whether differences are consistent.
    • Confusing advertised limits with practical performance. A larger context window does not guarantee accurate use of all information within it. Evaluate recall of key information instead.
    • Looking only at averages. Average latency can conceal a small number of extremely slow requests.