How to Select LLMs: Quantitative Methods for Coding Capabilities and Interactive Experience
Selecting the right Large Language Model (LLM) for development requires quantifying both backend coding capabilities and frontend interactive experiences. This article outlines a structured evaluation framework, covering test condition standardization, backend metrics like first-pass rate and token consumption, frontend quality scoring, multi-model routing implementation, and scenario-based trade-off rules to help you make informed LLM selection decisions.
1. Standardize Evaluation Conditions First
Before comparing models, you must fix the tasks, prompts, parameters, and code snapshots. If conditions are inconsistent, the results cannot be compared. It is recommended to standardize the following: prompt templates, temperature (set to 0 or 0.2), code repository snapshots, and test set versions. Each model should run the same set of tasks, with no fewer than 30 tasks covering CRUD operations, algorithms, concurrency, and exception handling.
2. Backend Code Capability: Three Metrics
- First-pass rate: The proportion of tasks where the model generates code that passes all defined tests in a single attempt. Passing criteria include three items: all unit and integration tests pass, static analysis shows no errors, and security scans reveal no high-risk vulnerabilities.
- Fix rounds: The number of rounds required to pass all tests by feeding failed test logs and error stack traces back to the model. The upper limit is set to 5 rounds; exceeding this limit is recorded as a failure.
- Token consumption: The median of the sum of input and output tokens for each task. Tokens consumed in each round of the fix process must be included.
The cost per task is calculated using the following formula:
Cost per task = Input Tokens × Input Price ÷ Billing Unit + Output Tokens × Output Price ÷ Billing Unit
Prices for different models should be converted to the same currency and billing unit (e.g., per million tokens). The procurement budget can be estimated by multiplying the median cost per task by the projected daily call volume.
3. Selection Table Template
The table below can be copied and used directly. Two rows are examples with placeholder values, not actual test results.
| Model | Tasks | First-pass Rate | Median Fix Rounds | Median Tokens | Cost per Task | Conclusion |
|---|---|---|---|---|---|---|
| Model A (Example) | 30 | 70% | 1 | 8,000 | Calculate via formula | Candidate |
| Model B (Example) | 30 | 50% | 3 | 15,000 | Calculate via formula | Eliminated or fallback only |
4. Frontend Generation Quality Scoring Table
Backend metrics cannot reflect interface quality, so the frontend must be scored separately. Score each dimension from 1 to 5, then sum them up based on weights.
| Dimension | Weight | Scoring Criteria |
|---|---|---|
| Runnability | 25% | 5 points: Runs directly without errors; 1 point: Cannot start |
| UI Fidelity | 20% | Check layout, spacing, and color against design mockups |
| Interaction Correctness | 25% | Whether form validation, button states, loading, and error prompts meet requirements |
| Accessibility | 10% | Whether semantic tags, keyboard operations, and contrast meet standards |
| Code Maintainability | 20% | Whether component splitting is reasonable, naming is clear, and code duplication is low |
Weighted Score = Σ(Dimension Weight × Dimension Score) ÷ 5 × 100
Example: A model scores 5, 4, 4, 3, and 4 across the five dimensions. The weighted score is (0.25×5 + 0.20×4 + 0.25×4 + 0.10×3 + 0.20×4) ÷ 5 × 100 = 83. This is a calculation example, not actual test data.
Scoring should be done independently by two people. If the score difference exceeds 1 point, align the scoring criteria first and then re-score.
5. Multi-Model Routing: Timeout, Retry, and Fallback
The code below is a routing skeleton. call_model needs to be replaced with the SDK call of the provider you are using.
import asyncioimport randomclass ModelError(Exception):"""Model call failed."""async def call_model(model: str, prompt: str) -> str:"""Replace with the actual SDK call, this is just a placeholder."""raise NotImplementedErrorasync def call_with_retry(model: str, prompt: str,timeout_s: float = 60.0,max_retries: int = 2,base_delay: float = 1.0) -> str:last_error = Nonefor attempt in range(max_retries + 1):try:return await asyncio.wait_for(call_model(model, prompt), timeout=timeout_s)except (asyncio.TimeoutError, ModelError) as e:last_error = eif attempt < max_retries:# Exponential backoff with random jitter to avoid simultaneous retriesawait asyncio.sleep(base_delay * 2 ** attempt + random.uniform(0, 0.5))raise ModelError(f"{model} call failed, retried {max_retries} times: {last_error}")async def route(prompt: str, chain=("primary-model", "backup-model", "small-model")):"""Try the model chain in order, falling back to the next when the previous one fails."""errors = []for model in chain:try:return model, await call_with_retry(model, prompt)except ModelError as e:errors.append(str(e))raise ModelError("All models failed: " + " | ".join(errors))
Note the following when using it:
- When the retry count is 2, a single model is called a maximum of 3 times. Retries increase token consumption and must be included in the cost.
- Only retry on timeouts and temporary errors. Retrying on authentication failures or parameter errors is meaningless; differentiate these two types of errors in
call_modeland throw permanent errors directly. - The timeout duration should be adjusted according to the task length. Code generation tasks usually require longer timeouts.
- The output of the fallback model must be re-scored; do not assume it has the same quality as the primary model.
6. Trade-off Rules for Code Capability and Interactive Experience
Determine the scenario first, then determine the weights for the two types of metrics.
- Backend services, data processing: Code capability accounts for 70%, interactive experience for 30%. Here, interactive experience refers to the clarity of API documentation and the readability of error messages.
- Frontend prototypes, internal tools: Code capability accounts for 40%, interactive experience for 60%.
The following are starting thresholds that can be adjusted based on business risk:
- Models with a first-pass rate lower than 60% will not enter the backend candidate list.
- Models with a frontend weighted score lower than 70 will not enter the frontend candidate list.
Example: A team building an internal reporting page has a model with a comprehensive code capability score of 75 and a frontend weighted score of 85. Calculated using the frontend scenario weights, the comprehensive score = 0.4 × 75 + 0.6 × 85 = 81.
7. Risk Checklist
- Model version drift: After providers update models, outputs will change. The test set must be re-run after every update.
- Sample bias: Public algorithm questions may have already appeared in the model’s training data, inflating scores. It is recommended to include real business tasks from your internal team.
- Cost miscalculation: Looking only at the unit price per call may overlook total token consumption costs.
