Practical LLM Evaluation for New-Generation Models: Hallucination, Code Generation, and Character Handling

    As large models enter quarterly iteration cycles, engineering teams need evaluation methods that go beyond aggregate leaderboard scores. This article explains how to assess capability curves, design evaluation sets using repeated sampling, separate reasoning and non-reasoning modes, build zero-tolerance multi-step tests, and evaluate context hallucination, code generation, and character-processing tasks. It also covers cost, concurrency, quota constraints, observability, compliance, common evaluation mistakes, and a practical deployment checklist.

    When large models move into quarterly iteration cycles, engineering teams often face three questions: How should LLM evaluation be designed? How should evaluation sets be selected? How should first-pass code quality be validated? If teams rely only on aggregate leaderboard scores, they may mistake average improvement for business readiness. What matters more is the shape of the capability curve: whether the model remains stable on simple tasks, zero-tolerant on multi-step tasks, faithful over long inputs, correct on code and character tasks, and deployable under cost and quota constraints.

    1. Evaluation focus: from total score to capability curve

    Vendor launch events often emphasize phrases such as “catching up with the top tier” or “entering the first tier.” These claims have limited value for engineering teams because tier rankings are coarse aggregate averages. They can hide the long-tail capabilities that determine whether a model succeeds in production.

    A model may lead overall while remaining weak at extracting information from the middle of long contexts. Another model may lag slightly in aggregate ranking but perform clearly better on one-shot code compilation. The first weakness can cause factual errors in retrieval-augmented question answering. The second determines whether a coding assistant needs multiple repair rounds.

    For each generational upgrade, evaluation should therefore move from “total-score comparison” to four concrete questions:

    • Does the capability lower bound rise, rather than only the mean?
    • Do error rates converge on low-difficulty, multi-step, zero-tolerance tasks?
    • Does output style change, especially average output length and the resulting cost?
    • Do service-side concurrency, quotas, and gradual rollout strategies affect availability?

    2. Three principles for evaluation design

    2.1 Replace single-shot passing with repeated sampling

    A single successful call is almost not evidence. If the same task is sampled three times and the model passes only once, that capability is usually not usable in real business scenarios. Online users do not accept an answer because a third attempt might eventually succeed.

    A reasonable approach is to repeat each task several times and report:

    • First-attempt pass rate, approximately pass@1, which reflects usability without retries.
    • Majority pass rate, which shows whether passing is the dominant behavior rather than a lucky exception.
    • Worst-case score, which represents tail risk and directly affects incident rates.

    The gap between these values is often more diagnostic than the average itself. If the first-attempt pass rate is high but the worst-case result across repeated samples remains poor, the improvement mainly comes from a rightward shift in the probability distribution. Persistent failure cases have not been truly fixed.

    In the example below, call and score are placeholders. call(prompt) should be replaced with a real model call. score(prompt, answer) returns 0 or 1, where 0 means failure and 1 means pass.

    1. import statistics
    2. def call(prompt): # Placeholder: replace with a real model call
    3. return "Sample answer"
    4. def score(prompt, answer): # Placeholder scorer: return 0 or 1
    5. # Example: return 1 only when the answer matches the expected text.
    6. return 1 if answer == "Sample answer" else 0
    7. def evaluate(prompts, call_fn=call, score_fn=score, n=5):
    8. rows = []
    9. for p in prompts:
    10. scores = [score_fn(p, call_fn(p)) for _ in range(n)]
    11. rows.append({
    12. "id": p.id,
    13. "pass_at_1": scores[0],
    14. "majority_pass": sum(s > 0 for s in scores) > n / 2,
    15. "worst": min(scores),
    16. "mean": sum(scores) / n,
    17. "std": statistics.pstdev(scores),
    18. })
    19. return rows

    2.2 Keep reasoning and non-reasoning modes in separate tables

    For the same model generation, enabling explicit reasoning and disabling it can produce structural differences. Reasoning mode often performs better on multi-step inference and complex algorithms, but latency and token consumption rise significantly. Non-reasoning mode is usually more suitable for intent recognition, structured extraction, formatting, and other low-risk, high-concurrency scenarios.

    Mixing both modes in one leaderboard table produces misleading conclusions. Evaluation tables should be split into at least two categories:

    • Deep reasoning
    • Low-latency direct output

    If the model produces long chains of thought, additional evaluation is needed for sensitive information leakage, log redaction, and cost limits. These issues should be reviewed before deployment rather than handled after launch.

    2.3 Deliberately design zero-tolerance tasks

    The most informative tasks are not always the hardest ones. They are often tasks where every step is simple, but one wrong step causes the whole output to fail. Common forms include:

    • List assignment problems, such as draws, rotations, or reconciliation, which require complete traversal in order without duplicates or omissions.
    • Multi-condition filtering, where a small misunderstanding of any condition produces the wrong result set.
    • Row-by-row table verification and difference localization, which require both row-level accuracy and global consistency.

    These tasks have no shortcuts. They do not depend on deep conceptual understanding. They directly test the stability of long-sequence execution. They are especially sensitive to hallucination: the model may not fail because it cannot calculate, but because it misreads the input.

    Example: list rotation

    Input:

    1. ["Alice", "Bob", "Carol", "Dan"]

    Rule: rotate starting from Alice in list order. Each person is assigned for 2 consecutive days. Weekends do not pause the rotation. Output the schedule for the next 8 days.

    Expected output:

    1. ["Alice", "Alice", "Bob", "Bob", "Carol", "Carol", "Dan", "Dan"]

    Scoring script:

    1. def judge_rotation(names, span, days):
    2. expected = []
    3. index = 0
    4. for day in range(days):
    5. expected.append(names[index // span])
    6. if (day + 1) % span == 0:
    7. index += 1
    8. return expected
    9. # In real scoring, compare the model output item by item. Any mismatch is a failure.

    3. Context hallucination: visible progress, but boundaries must be reported honestly

    Context hallucination refers to cases where model output is inconsistent with the given material. It is not the generation of entirely new world knowledge. It is usually incorrect citation of existing text, wrong attribution, omission of qualifications, or misaligned numbers. It is especially damaging in retrieval-augmented generation, contract review, and log analysis, because users assume the model has read the source text.

    Context hallucination can usually be decomposed into two sub-capabilities:

    1. Multi-source information extraction: locating key fields scattered across long materials and correctly associating them.
    2. Long-text summarization and fidelity: preserving key qualifiers during compression without altering quantities, time ranges, or subjects.

    New flagship models may improve noticeably in these areas, especially in summarization tasks where they need to balance detail preservation with avoiding external information. However, conclusions should be qualified. Improvement depends on task type, model version, prompt design, material length, and sampling count. A single demo should not be extrapolated into a universal result.

    If improvement appears mainly in first-attempt pass rate while worst-case behavior does not improve compared with the previous generation, remaining failures are likely concentrated in a small number of difficult cases.

    At the engineering level, mitigation does not rely on the model becoming indefinitely stronger. It converts uncontrolled probability into controllable verification:

    • Citation backfill: require each key conclusion to include a source fragment or location marker, then verify that the fragment exists in the input.
    • Field-level constraints: use structured output and fixed schemas to reduce freedom, turning free text into field filling.
    • Second-pass verification: use a cheaper small model or rule engine to check extraction consistency. If inconsistent, retry or degrade.
    • Deterministic fallback: for quantities, amounts, dates, and similar key fields, prioritize deterministic code. Let the model focus on semantic understanding and structuring.

    4. Code generation: from “can run” to “passes on the first try”

    Code generation is a major investment area for flagship models and one of the easiest capabilities to quantify. Code evaluation should not rely only on whether the code “looks correct.” A more useful approach uses three progressive thresholds:

    • Threshold 1: compilable or parseable. Across multiple samples, the model should produce code that at least passes syntax checks and is accepted by the compiler. This indicates engineering usability.
    • Threshold 2: test case pass rate. Compile, run, and execute unit tests in a controlled sandbox. Deterministic results replace subjective judgment. If complex algorithm tasks approach top-tier pass rates, reasoning and boundary handling are already mature enough for engineering use.
    • Threshold 3: repository-level engineering ability. This includes cross-file refactoring, following existing code style and dependency constraints, generating runnable migration scripts, and filling in tests. This capability remains a common weakness and cannot be reflected by single-task evaluation.

    The scorer must run in an isolated container. External network access should be disabled, and time and memory limits should be enforced. This prevents model-generated infinite loops or unauthorized calls from contaminating the evaluation environment.

    In the example below, sandbox.run returns a RunResult. pass_count is the number of passed test cases, total_count is the total number of test cases, and stage indicates the failure stage or final state.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class RunResult:
    4. stage: str # "compile_error" / "lint_error" / "test_error" / "ok"
    5. pass_count: int
    6. total_count: int
    7. non_deterministic: bool = False
    8. def judge(code: str, tests: list, sandbox) -> dict:
    9. # sandbox.run returns a RunResult.
    10. r: RunResult = sandbox.run([
    11. "compile", code,
    12. "lint", code,
    13. "test", code, tests,
    14. ], timeout=30, net=False)
    15. return {
    16. "compiled": r.stage != "compile_error",
    17. "lint_passed": r.stage not in ("compile_error", "lint_error"),
    18. "pass_rate": r.pass_count / max(1, r.total_count),
    19. "flaky": r.non_deterministic,
    20. }

    Repository-level evaluation takes longer. It usually requires preparing dependency snapshots and baseline tests for each repository. This work should be scheduled in advance, not compressed into a few afternoons.

    5. Character handling: failures come from “misreading,” not “miscalculating”

    Character tasks include counting characters, reversing strings, changing case, handling escapes, splitting by delimiters, and locating the Nth character. These tasks look simple, but they are a natural weak area for models. Tokenizers split text into subword units, so models see tokens rather than characters. Operations that depend on exact character boundaries therefore tend to show systematic bias.

    New-generation models usually improve slightly on these tasks. Simple forms such as pure ASCII, no line breaks, and short strings can often be handled reliably. Complex forms such as Chinese, emoji, combining characters, multi-line inputs, and escape sequences still show a wide gap between the best and worst cases.

    When observing failures, the root cause is often not reasoning error. The model misreads characters at the input stage, and subsequent reasoning faithfully carries the wrong conclusion forward.

    This has an important engineering implication: increasing difficulty is not the solution. The solution is to turn the task from a generation problem into a tool-call problem. Character counting should be handled by string-length functions. Splitting should be handled by split interfaces. Format conversion should be handled by serialization libraries. The model should only decide which tool to call and what parameters to use.

    However, external tools are not a boundary-free solution. When calling methods such as len or split, teams must define Unicode encoding, combining characters, and emoji counting rules. For example, é may be a single precomposed character, or it may be e plus a combining accent. An emoji may also consist of multiple code points or a zero-width joiner sequence. If evaluation criteria are inconsistent, implementation details may be mistaken for model capability differences.

    6. Cost, concurrency, and quotas: hidden costs of generational upgrades

    Capability upgrades often come with tighter service constraints. This part is often ignored in evaluation articles, but it directly affects architecture decisions.

    Output length inflation is the most direct issue. Stronger reasoning often appears as longer thinking processes and more complete answers. If unit prices remain unchanged or rise, an increase in average output tokens can multiply actual spending. Cost budgets must model input and output tokens separately and impose upper limits on output length.

    A simple estimation formula is:

    1. Total cost =
    2. input tokens × input price
    3. + output tokens × output price
    4. + retry cost
    5. + rate-limit degradation cost

    Example: assume one request has 2,000 input tokens and 800 output tokens. The input price is 0.02 CNY per 1,000 tokens, and the output price is 0.08 CNY per 1,000 tokens. The retry rate is 10%.

    Base cost per request:

    1. 2000 / 1000 × 0.02 + 800 / 1000 × 0.08
    2. = 0.04 + 0.064
    3. = 0.104 CNY

    With a 10% retry rate, expected cost is approximately:

    1. 0.104 × 1.1 = 0.1144 CNY

    If caching, rule-based fallback, or lightweight model degradation is available, some cost can be reduced further. However, capacity planning should first use conservative estimates, then observe real output-length distributions and retry rates under production traffic.

    Concurrency and quotas also tend to tighten. It is common for a new model release to face limited compute capacity. Typical measures include limiting concurrency for regular users, making the latest model available only to the highest subscription tier, and gradually releasing capacity. These policies may be reasonable at the capacity level, but they require client-side support:

    • Queue and serialize requests, and model concurrency limits explicitly as semaphores.
    • Use exponential backoff retries, and distinguish rate-limit errors from content errors. Content errors should not be retried blindly.
    • Cache results and deduplicate semantically to block repeated requests before they reach the model.
    • Use tiered routing: high-risk tasks go to the flagship model, while low-risk high-concurrency tasks go to a lightweight model or local rules.

    The routing example below returns explicit dictionaries to avoid undefined variables:

    1. def route(task):
    2. if task.risk == "high" or task.needs_deep_reasoning:
    3. return {"model": "flagship", "mode": "reasoning"}
    4. if task.structured and task.len < 2000:
    5. return {"model": "cheap", "mode": "direct"}
    6. return {"model": "cache_or_rule", "mode": "fallback"}

    Teams should also build observability. By scenario, track first-attempt pass rate, average output length, cost per request, rate-limit ratio, and fallback hit rate. Without these metrics, the question of whether a new model generation is worth upgrading can only be answered by intuition.

    When evaluation corpora, logs, and monitoring data are involved, compliance also matters. Evaluation inputs and output logs should be redacted or collected with data minimization. Access control should distinguish development, evaluation, and production environments. User privacy, contract text, and internal data should not be exposed to evaluation systems without authorization.

    7. Evaluation dimension comparison table

    To make evaluation results easier to reuse, a comparison table can be added before the deployment checklist.

    Evaluation dimension Collection method Acceptance metric Pass condition
    Context hallucination Long-material extraction, summarization, citation backfill Field accuracy, citation traceability, worst-case error count Key fields are not wrong, citations are locatable, no external information is introduced
    Code generation Sandboxed compilation, linting, unit tests Compilation pass rate, test pass rate, first-attempt pass rate First-attempt pass rate meets the target, and key test pass rate is not below baseline
    Character handling Counting, splitting, escaping, locating Consistency rate with deterministic tool results Complex character scenarios have explicit rules, and the tool-call approach is reproducible
    Stability Repeated sampling on the same task pass@1, majority pass rate, worst case First-attempt pass rate improves and worst-case behavior does not worsen
    Cost and concurrency Load testing, gradual rollout, real traffic Input and output tokens, retry rate, rate-limit rate, fallback hit rate Per-request cost is controllable, rate limits have backoff, fallback exists
    Compliance Log audit, permission checks Redaction rate, access control, data minimization No plaintext sensitive data, least-privilege access, evaluation is auditable

    8. Common evaluation mistakes

    When selecting a model or upgrading versions, the following mistakes are common:

    • Looking only at total scores while ignoring the lower bound and tail risk.
    • Testing only once and treating a lucky success as stable capability.
    • Mixing reasoning and non-reasoning modes, leading to misleading conclusions.
    • Reporting only averages without reporting worst-case behavior.
    • Scoring code generation subjectively instead of using compilation, linting, and unit tests.
    • Failing to define Unicode, emoji, and combining-character rules for character tasks.
    • Counting only input tokens without evaluating output-length inflation.
    • Ignoring concurrency quotas, leading to queuing, rate limiting, or cascading failures after launch.
    • Failing to redact evaluation logs, creating compliance risk.

    9. Deployment checklist

    • Evaluation sets include separate reasoning and non-reasoning results, without mixing them.
    • Each task is sampled multiple times, and the report includes first-attempt pass rate, majority pass rate, and worst case.
    • A dedicated set of zero-tolerance multi-step tasks measures stability at the tail.
    • Context hallucination has its own evaluation set, with citation backfill and field-level validation.
    • Code evaluation compiles and runs unit tests in an isolated sandbox, and the scorer is deterministic and reproducible.
    • Character tasks prefer deterministic tool calls, with explicit Unicode rules.
    • Cost accounting includes both input and output tokens, and output length limits are set.
    • The client implements rate-limit backoff, result caching, and tiered model routing.
    • A monitoring dashboard tracks pass rate, cost, and rate limiting by scenario.
    • Repository-level engineering evaluation is planned, with time reserved for environment preparation.
    • Evaluation corpora, logs, and monitoring data are redacted, minimized, and access-controlled.

    10. Conclusion

    To evaluate a new-generation flagship model, rather than debating its leaderboard position, answer three concrete questions:

    1. How much has the capability lower bound improved?
    2. How severe are failures in the worst case?
    3. What is the cost per unit of effective output?

    The current generation of models has crossed the engineering usability threshold in areas such as hallucination control and first-pass code generation. However, tail risk has not been eliminated. Character-level and repository-level capabilities still need support from external engineering methods.

    The practical way to turn generational upgrades into business value is to constrain uncontrolled probability with verification, caching, routing, and deterministic tools.