LLM Capability Evaluation in Practice: Reasoning, Hallucination, and Code Testing
Models iterate faster than most evaluation systems can be built, and public leaderboards rarely reflect real business data. This article takes a practical, methodology-first approach to LLM evaluation. It breaks testing into four key capability areas—logical reasoning, context hallucination control, coding ability, and character processing—and explains how to separate intrinsic difficulty from step-driven difficulty, track Pass@1, full-pass rates, and worst-case scores, and combine metrics, sampling strategy, and service-side constraints into conclusions that hold up to scrutiny. It also covers reproducible judges with code samples, choosing between reasoning and non-reasoning modes, cost and capacity planning, evaluation under concurrency limits, and a cloud-based evaluation pipeline, closing with common pitfalls and a deployment checklist.
Introduction: As Versions Ship Faster, How Can Evaluation Keep Up?
Over the past two years, the focus of general-purpose LLM capabilities has shifted from single-point breakthroughs to multi-dimensional coordination. Depth of reasoning, faithfulness to context, the ability to get code right on the first try, and fine-grained character-level handling together determine whether a model can actually be embedded into production workflows.
For engineering teams, the hard part is that models iterate far faster than evaluation systems can be built. Public leaderboards offer broad coverage but struggle to reproduce real business data, and users’ hands-on experience often disagrees with leaderboard rankings. Rather than chasing version numbers, it pays to build a reproducible, quantifiable evaluation system of your own: one that produces comparison results the day a new model ships, and that grounds day-to-day tuning, prompt changes, and model swaps in evidence rather than gut feeling.
This article is not about any specific product. Instead, it approaches LLM evaluation from a methodology standpoint—outlining how to design an evaluation system, breaking down test methods for four key capability areas, and explaining how to combine metric aggregation, sampling strategy, and service-side constraints to reach conclusions that hold up to scrutiny.
Part 1: Answer Three Questions First
Every evaluation round should serve a clear engineering decision. Work through these three questions in order:
- Is it usable? On real tasks, can the model return a correct result in a single shot?
- Is it stable? Across repeated sampling, are results consistent, and is the worst case acceptable?
- Can we afford it? Are token consumption, response latency, and concurrency capacity within budget?
Choose your dimensions and metrics around these three questions, and evaluation results can genuinely become inputs for model selection, routing, and capacity planning.
Part 2: Evaluation Design for Four Key Capabilities
2.1 Logical Reasoning: Separate Difficulty from Step Count
Failures on logical reasoning tasks fall into two broad categories:
- Intrinsic difficulty: The task requires domain knowledge, multi-step computation, or reasoning over complex constraints—for example, logic puzzles, trip planning, or scheduling and rostering.
- Extrinsic difficulty: The task itself is not hard, but it involves a large number of intermediate steps—for example, extracting dozens of clauses from a full contract and judging each one, or deriving a long procedure by rule.
Build separate question sets for each and track them separately. In engineering practice, the latter often matters more, because it maps directly to the multi-stage tasks that show up in real business. The more steps there are, the more easily small per-step deviations accumulate layer by layer, and the higher the probability that errors get amplified.
With prompts and sampling parameters held constant, resample the same question multiple times and track separately:
- Pass@1: Measures average performance and the usability of a single call.
- Full-pass rate over k runs: Measures stability.
- Worst-case score: Reflects long-tail risk.
The worst case matters especially. A business system can’t predict which request will fail; if the worst-case result is roughly the same as the previous generation, then even a clearly better average will still surface as occasional errors that users notice after launch. This kind of gap is usually a key signal in evaluation.
2.2 Context Hallucination Control: Faithfulness Is the Foundation of Reliability
Context hallucination means the model introduces information in its answer that is absent from the input material or contradicts it. The harm is especially pronounced in tasks that are not deeply reasoned but involve a large number of intermediate steps: missing a key field during multi-source extraction, misattributing facts in a long-text summary, or inventing details in retrieval-augmented Q&A—all of these cause downstream decisions to rest on false premises.
For evaluation, I recommend:
- Build a reference-answer table: For each question, list the facts that must be included and the wrong facts that must never appear.
- Automate the check: Use exact matching or regex rules to count fact recall and the number of incorrect facts.
- Collect specialized samples: Build dedicated question sets for scenarios such as multi-source extraction, long-text summarization, and merging information across paragraphs.
- Set layered goals: First confirm whether the overall score distribution has shifted upward, then track the perfect-score rate and worst case to see whether the capability floor has improved too.
If an improvement shows up in only a few samples, it is more of a ceiling lift than a stability lift—and that is still some distance from being production-ready.
Two more engineering lessons are worth noting:
- Output structure itself can trigger hallucination. If you require JSON output and the model supports structured output, prefer to enable that capability, and automatically retry or fall back when parsing fails, so you avoid “correct content, wrong format.”
- Watch for invisible correction. Post-processing—rule-based cleaning, field validation, format repair—can mask a model’s real errors and inflate evaluation scores. During evaluation, record raw output and final output separately, and track them separately.
2.3 Coding Ability: From “Runs” to “Correct on the First Try”
Code generation needs to be measured in layers. Break the results into four levels and record the pass proportion at each:
- L1 — Syntactically valid: The code parses with no obvious syntax errors.
- L2 — Compiles/runs: It passes compilation or interpreted execution, with dependencies and interfaces resolving normally.
- L3 — Passes functional tests: It produces entirely correct output on the given test cases (including edge cases).
- L4 — Meets quality bar: Algorithmic complexity meets requirements, exception handling and resource release are complete, and it can be integrated into an existing project.
Beyond the level-by-level breakdown, track two more metrics:
- First-pass rate: The proportion of first outputs that reach L3 or above, which directly reflects day-to-day efficiency.
- Multi-sample stability: If repeated sampling always yields at least compilable code, the model has the basic foundation for self-correction and iteration.
Complex algorithmic problems should specifically probe boundary conditions, extreme inputs, and complexity constraints. Scores on these problems cluster near top-tier models, so they are often what technical teams care about most. Engineering-code testing involves dependency management, runtime environments, and execution safety; it is costly and slow, so it can be added as an advanced stage once the evaluation system has stabilized.
2.4 Character Processing: Simple Tasks Test Stability, Complex Tasks Test Error Sources
Character and string handling looks basic, but it is a touchstone for a model’s ability to execute programs with precision. Typical tasks include character counting, string reversal, case and full-width/half-width conversion, deduplication and sorting, and inserting or replacing characters at specific positions. Three points matter for evaluation:
- Simple tasks—look at stability: These have well-defined algorithms, and repeated sampling should be perfect every time. If results fluctuate, the basic execution ability is not yet solid.
- Complex tasks—look at the distribution: For problems that require multiple transformations, watch the gap between upper and lower bounds, and use the model’s reasoning trace to locate the failing step.
- Error attribution: The common root cause is the model slightly “misreading” or “misremembering” a character, which throws off all subsequent computation.
The table below shows an illustrative analysis framework. The entries are fictional examples that do not correspond to any specific model; they show how layered statistics reveal the structure of a model’s capability:
| Task type | Example task | Simple-case stability | Complex-case score range | Main failure cause |
|---|---|---|---|---|
| Character counting | Count occurrences of a given character in a string | High, consistent across samples | Narrow | Character-count drift in long strings |
| Character transformation | Shift each character in a string by one position | High | Medium | Errors at boundary characters |
| Multi-step combination | Deduplicate, then sort, then slice | Medium-high | Wide | Misread characters in intermediate steps |
| Format conversion | Mixed case and full/half-width conversion | High | Medium | Deviations in rule-boundary judgments |
When a model has mature function-calling ability, the more robust engineering approach is to let the model generate the calling code and then have a deterministic program execute it. This keeps the flexibility of the model’s intent understanding while using a program to guarantee precise results.
Part 3: Metrics and Statistics: Making Scores Hold Up to Scrutiny
3.1 Core Metrics
| Metric | Definition | Main use |
|---|---|---|
| Pass@1 | Proportion of single calls that pass the test | Measures average usability |
| Pass@k / full-pass over k runs | Proportion that passes at least once (or all) across k samples | Measures stability and the capability ceiling |
| Error-rate range | Lowest and highest scores across samples | Exposes long-tail risk |
| Average output length | Average tokens generated per call | Estimates cost and latency |
| P50/P95 latency | Median and 95th-percentile response time | Assesses user experience and capacity planning |
3.2 Statistical Guidelines
- Fix sampling parameters: Use the same settings for each round, including randomness parameters, maximum output length, and reasoning-mode on/off.
- Keep question IDs and content confidential: Manage the internal question set with version control only, to prevent overlap between model training data and evaluation questions from inflating scores, and to keep prompts from being over-optimized for.
- Be transparent about definitions and sample size: When presenting comparison results externally, state which metrics come from reasoning mode versus non-reasoning mode, the scope of the questions, and the sample count, to avoid one-sided interpretation.
Part 4: Evaluation Workflow and Code Implementation
4.1 Standard Workflow
- Build the question set: Categorize by capability and difficulty. Public questions are for tracking trends; a self-built private set is for final decisions.
- Develop judges: Write deterministic judging logic for each question type; two illustrative examples follow.
- Batch execution: Fix sampling parameters, call multiple times, and record the complete raw output.
- Aggregate results: Generate comparison reports by model, mode, and task type, and keep each sample’s raw output for later review.
4.2 Judge Examples
# Example 1: Multi-field extraction — judge against a fact table (illustrative code)def judge_extraction(output, must_include, must_not_include):# Validate the output structure first, then check the factsif not isinstance(output, dict):return Falsefor key, expected in must_include.items():if output.get(key) != expected:return Falsefor bad in must_not_include:if bad in str(output):return Falsereturn True# Example 2: Character processing — exact-match judging (illustrative code)def judge_chars(output, expected, normalize=lambda s: s.strip().lower()):return normalize(output) == normalize(expected)
4.3 Result Aggregation and Reporting
# Example 3: Aggregate core metrics (illustrative code; see the full code listing at the end)def summarize(model, mode, records):# records: [{"task": ..., "pass": True, "out_tokens": 820, "latency_ms": 6300}, ...]groups = {}for r in records:g = groups.setdefault(r["task"], {"n": 0, "pass_cnt": 0,"out_tokens": [], "latency": []})g["n"] += 1g["pass_cnt"] += int(r["pass"])g["out_tokens"].append(r["out_tokens"])g["latency"].append(r["latency_ms"])total = sum(g["n"] for g in groups.values())pass1 = sum(g["pass_cnt"] for g in groups.values()) / totalall_pass = sum(g["pass_cnt"] == g["n"] for g in groups.values()) / len(groups)out_tokens = [r["out_tokens"] for r in records]latency = sorted(r["latency"] for r in records)return {"model": model,"mode": mode,"pass@1": round(pass1, 4),"k_full_pass": round(all_pass, 4),"avg_out_tokens": round(sum(out_tokens) / len(out_tokens), 1),"p95_latency_ms": latency[min(len(latency) - 1, int(len(latency) * 0.95))],}
A report should include at least five items: Pass@1, full-pass rate over k runs, average output tokens, P95 latency, and per-question cost.
Part 5: From Evaluation Results to Engineering Decisions
5.1 Mode Selection: Use Reasoning and Non-Reasoning Modes Together
Many new-generation models offer two calling modes:
- Non-reasoning mode: The model produces an answer directly—short output, fast response, low cost.
- Reasoning mode: The model first emits a longer reasoning trace before answering—token consumption and latency rise noticeably, but accuracy on complex tasks is usually higher.
Run evaluation in both modes and derive a capability profile for each. For routing, you can reference a strategy like the following and keep calibrating it against real data:
# Example 4: Illustrative logic for selecting a model mode based on task features (illustrative code)def select_mode(task):# Rules or a lightweight classifier can both workif task["complexity"] == "high" or task["steps"] > 5:return "reasoning_on" # Long-chain, high-difficulty tasksif task["type"] in ("extraction", "format"):return "reasoning_off" # Patterned, low-reasoning tasksreturn "reasoning_off" # Prioritize cost for simple Q&A
5.2 Cost Model and Capacity Planning
- Cost estimation: Per-call cost = input tokens × input price + output tokens × output price. Output grows noticeably in reasoning mode; if input and output are priced differently, the cost amplifies further. You can quickly estimate a monthly budget as “average output tokens × call volume.”
- Capacity estimation: With a concurrency limit P and average response time T (in seconds), theoretical throughput is about P / T requests per second. For example, at concurrency 1 with an average of 60 seconds per call, the system handles at most about 1 request per minute, and queuing during peak hours is inevitable.
- Trade-offs for high-cost tasks: Batch tasks (offline reports, code review, log analysis) can run off-peak with timeouts and retries configured. Real-time interactive tasks should set output-length caps, streaming output, and queue prompts.
- Cost-effectiveness assessment: A smaller model combined with task decomposition, retrieval augmentation, and programmatic validation can approach a large model’s results in many scenarios, so evaluate it alongside the large-model option when selecting.
5.3 Evaluation Practices Under Concurrency Constraints
When the evaluation service is sensitive to concurrency, consider the following:
- Run in batches, serially: Control the concurrency level to avoid triggering rate limits that fail many requests and pollute the evaluation data.
- Record service status faithfully: Track rate-limiting, queuing, and timeouts separately, distinct from model capability scores.
- Compare in a fixed environment: Complete model comparisons within similar time windows, and record the server-side version to reduce the influence of external factors.
# Example 5: Call with retry and backoff (illustrative code)def call_with_retry(client, prompt, params, max_retries=3):for attempt in range(max_retries + 1):try:return client.chat(prompt, **params) # chat is a unified model-calling interfaceexcept RateLimitError:if attempt == max_retries:raisetime.sleep(2 ** attempt) # Exponential backoff: 1s, 2s, 4s
5.4 Cloud-Based Evaluation Pipeline
Model evaluation is an engineering system that can run continuously, and it can be built from a combination of general-purpose cloud products, such as:
- Object storage: Store versioned question sets, raw outputs, and evaluation reports.
- Message queues: Decouple task submission from execution, smooth out peaks, and keep evaluation tasks from crowding out online resources.
- Container platform: Run judges and batch evaluation jobs, scaling elastically on demand.
- Logging, monitoring, and alerting: Continuously collect call volume, success rate, latency, and token consumption, and alert promptly when model behavior turns anomalous.
Baidu AI Cloud provides model services along with a range of general-purpose cloud capabilities. Enterprises can build on these foundations to stand up their own evaluation platform and close the loop across evaluation, deployment, monitoring, and regression.
Part 6: Common Pitfalls
- Looking only at averages: A higher average does not mean a higher floor; the worst case determines whether the business can deliver reliably.
- Assuming one model does everything: Different models have different strengths, so combine them and route by scenario.
- Leaderboard-ism: Public leaderboards cannot replace evaluation on real business data.
- Ignoring output length: If evaluation tracks only accuracy and not output tokens, cost easily spirals out of control.
- Ignoring output format: When the business requires JSON or a fixed format, prefer to enable structured output and add parsing validation.
- Ignoring supporting services: Behind a usable model there is usually coordinated support for concurrency, rate limiting, stability, and cost control—engineering capability is itself part of evaluation.
Conclusion
The point of evaluation is not to rank models but to turn “gut feeling” into “evidence.” Break logical reasoning, context hallucination, coding ability, and character processing into measurable metrics, then layer on the two dimensions of stability and cost, and technical teams can keep their judgment intact amid fast version iteration.
For teams about to put this into practice, work through the following checklist:
- Map out your business scenarios and build a private question set covering the four capability areas.
- Write reproducible judges, and evaluate reasoning and non-reasoning modes separately.
- Make sure reports include Pass@1, full-pass rate over k runs, worst case, and token consumption.
- Use “mode routing + programmatic validation + output constraints” as engineering guardrails.
- Set quotas and capacity strategy based on concurrency and cost models.
- Plug evaluation into a cloud-based pipeline for continuous regression and calibration.
# Code listing: a complete, runnable example that aggregates Examples 1–4import timedef call_with_retry(client, prompt, params, max_retries=3):"""Model call with exponential backoff retry"""for attempt in range(max_retries + 1):try:return client.chat(prompt, **params) # chat is a unified model-calling interfaceexcept RateLimitError: # Define this exception per your model serviceif attempt == max_retries:raisetime.sleep(2 ** attempt)def judge_extraction(output, must_include, must_not_include):"""Multi-field extraction: judge against a fact table"""if not isinstance(output, dict):return Falsefor key, expected in must_include.items():if output.get(key) != expected:return Falsefor bad in must_not_include:if bad in str(output):return Falsereturn Truedef judge_chars(output, expected, normalize=lambda s: s.strip().lower()):"""Character processing: exact-match judging"""return normalize(output) == normalize(expected)def select_mode(task):"""Select a calling mode based on task features"""if task["complexity"] == "high" or task.get("steps", 0) > 5:return {"reasoning": "on"}return {"reasoning": "off"}def run_eval(client, dataset, params, k=3):"""Run batch evaluation and return per-item records"""records = []for case in dataset:mode = select_mode(case)# Resample the same case k times in the selected mode; disable sampling randomness during evaluationfor i in range(k):start = time.perf_counter()resp = call_with_retry(client, case["prompt"], {**params, **mode})latency_ms = (time.perf_counter() - start) * 1000if case["type"] == "extraction":passed = judge_extraction(resp["content"], case["must_include"],case["must_not_include"])else:passed = judge_chars(resp["content"], case["expected"])records.append({"task": case["id"], "pass": passed,"out_tokens": resp["usage"]["output_tokens"],"latency_ms": latency_ms})return recordsdef summarize(model, records):"""Aggregate core metrics: Pass@1, full-pass rate over k runs, tokens and latency"""groups = {}for r in records:g = groups.setdefault(r["task"], {"n": 0, "pass_cnt": 0})g["n"] += 1g["pass_cnt"] += int(r["pass"])total = sum(g["n"] for g in groups.values())pass1 = sum(g["pass_cnt"] for g in groups.values()) / totalall_pass = sum(g["pass_cnt"] == g["n"] for g in groups.values()) / len(groups)out_tokens = [r["out_tokens"] for r in records]latency = sorted(r["latency_ms"] for r in records)p95 = latency[min(len(latency) - 1, int(len(latency) * 0.95))]return {"model": model, "pass@1": round(pass1, 4),"k_full_pass": round(all_pass, 4),"avg_out_tokens": round(sum(out_tokens) / len(out_tokens), 1),"p95_latency_ms": round(p95, 1)}
