How to Evaluate and Select Large Language Models: A Practical Engineering Framework
This article presents a practical framework for evaluating and selecting large language models (LLMs) in engineering projects, replacing subjective rankings with measurable, repeatable, and auditable metrics. It covers task layering across six categories, building regression test sets from real business data, designing quality, stability, performance, and cost indicators, and applying scenario-specific practices for code generation, long-document understanding, translation, numerical reasoning, RAG, and content safety. It also recommends a routing and fallback architecture, a pre-launch checklist, and treating model selection as a continuous engineering process rather than a one-time ranking. The content is based on Baidu AI Cloud's general cloud capabilities where relevant.
1. Why Subjective Rankings Do Not Work in Engineering
In real projects, teams often run into the same debate: which large language model is actually “better.” These discussions usually stay at the level of personal experience, with small samples, inconsistent task distributions, and differently written prompts, so the conclusions are hard to reproduce. From an engineering perspective, model capability is not a scalar. It is a function that changes with task type, input length, language, domain terminology, and output format constraints. The same model may excel at code completion yet become unstable at structured extraction from long documents; it may produce fluent creative writing yet make mistakes in numerical reasoning and unit conversion.
For this reason, this article does not declare a “winner.” Instead, it provides an executable evaluation framework that turns “intuition” into engineering metrics that are measurable, repeatable, and auditable.
2. Start With Task Layering: Break “General Capability” Into Measurable Dimensions
Break business requirements into six task categories and evaluate each one separately:
- Code: completion, cross-file refactoring, unit test generation, defect localization.
- Text processing: summarization, rewriting, terminology unification, format conversion, structured extraction.
- Reasoning and computation: multi-step reasoning, numerical calculation, unit and dimensional consistency.
- Multimodal: image understanding, joint image-text retrieval, video and audio content understanding.
- Retrieval-augmented: question answering and root-cause analysis grounded in enterprise knowledge bases, logs, and monitoring data.
- Compliance and safety: sensitive content filtering, data minimization, audit trails.
The key benefit of layering is avoiding a single aggregate score that hides weaknesses. For example, a model that is faster at math problems offers almost no value if your business is contract clause extraction.
3. Build a Regression Test Set: Make Evaluation Repeatable
The evaluation set should come from real business data, not public question banks. A recommended structure:
{"case_id": "ext-0031","task_type": "structured_extraction","input": "contract text snippet (anonymized)","constraints": {"output_schema": "json","required_fields": ["party_a", "party_b", "term_months"],"max_tokens": 800,"language": "zh-CN"},"rubric": {"field_accuracy": 0.4,"format_compliance": 0.3,"latency_p95_ms": 0.2,"cost_per_1k_calls": 0.1}}
Engineering essentials:
- At least 100 samples per task type, covering long-tail and adversarial cases;
- Fix prompts, temperature, and other parameters; any change must be versioned;
- Record raw outputs to support later review and dispute resolution;
- Validate “format compliance” programmatically rather than by visual inspection.
4. Metric Design: Turn Experience Into Four Quantitative Categories
- Quality metrics: field-level accuracy, key-point coverage, terminology consistency, code compilability, and unit test pass rate.
- Stability metrics: result variance across repeated sampling of the same input, and performance degradation curves under long context.
- Performance metrics: time to first token, P95/P99 end-to-end latency, throughput per unit time.
- Cost metrics: cost per thousand calls, hidden cost from rework, and manual review hours.
An often-overlooked fact is that rework usually costs more than the unit price. If one model has a first-pass rate of 60% and another reaches 90%, the former may still be more expensive overall despite a lower unit price. A rough estimate:
Total cost ≈ unit price × number of calls / first-pass rate + manual review hours × labor rate
5. Practical Recommendations for Typical Scenarios
Code generation and refactoring: focus on cross-file context understanding, dependency version constraints, compilability of generated code, and security vulnerability rate. Add static checks and unit test gates to the pipeline; do not merge model output directly into the main branch.
Long text and document understanding: focus on effective utilization of the context window rather than the nominal length. In practice, “information loss in the middle sections” is common, so design a two-stage approach of segmented summarization plus a global index, and perform secondary validation on key fields.
Translation and terminology unification: first produce a draft with a general model, then normalize and polish it with a model that follows instructions strongly, and finally validate programmatically against a glossary. Explicitly prohibiting redundant punctuation and requiring consistent sentence patterns in the prompt can significantly reduce rework.
Numerical and multi-step reasoning: do not let the model “do mental math.” Externalize computation to code execution or a calculation engine, leaving the model responsible only for modeling and explanation, which greatly reduces dimensional and carry errors.
Retrieval-augmented and knowledge Q&A: keep authoritative data on the retrieval side and let the model only summarize and cite. Answers must include source snippets for auditing.
Content safety: filter both input and output, minimize and anonymize sensitive data upfront, and keep end-to-end audit trails.
6. Cost, Latency, and Architecture: Treat Models as Replaceable Components
A recommended “routing + fallback” architecture: split traffic by task type and risk level to different models; route low-value high-frequency requests to lightweight models and high-value low-frequency requests to stronger models; automatically fall back or escalate to humans when the primary path times out or quality falls short.
def route(req):if req.risk == "high" or req.task == "code_refactor":return strong_modelif req.tokens > 100_000:return long_context_modelreturn light_model
For the supporting engineering capabilities, general cloud service categories are recommended: object storage for evaluation sets and raw outputs, a message queue for request peak shaving, a container platform to host the inference gateway, logging and monitoring/alerting to track latency and failure rate, and a key management service to hold credentials. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the underlying platform.
7. Pre-Launch Checklist
- Does the evaluation set cover long-tail and adversarial cases;
- Is there programmatic format and schema validation;
- Are first-pass rate and rework rate thresholds set;
- Are multi-model routing and fallback switches in place;
- Are anonymization, minimization, and audit trails completed;
- Is dual version management established for both prompts and models;
- Is cost accounting done on a “rework-inclusive” basis.
8. Conclusion
Model selection is not a one-time ranking but a continuously running engineering process. Only by layering tasks, quantifying metrics, accumulating evaluation sets as assets, and making the architecture replaceable can you stay robust in an environment of rapid model iteration. To support the above process, you can build a closed loop for evaluation, routing, and monitoring based on Baidu AI Cloud’s general cloud product capabilities, turning “stronger” into “more suitable.”
