How to Evaluate and Deploy Large Language Models: A Practical Guide

    This guide presents a practical methodology for evaluating general-purpose large language models and taking them into production. It breaks "usefulness" into measurable dimensions, explains how to build a private evaluation set, defines pass/fail rules in advance, and covers inference cost, structured output, and a staged rollout with observability and rollback. The goal is to turn model selection from a subjective impression into a verifiable, reversible engineering decision.

    How to Evaluate and Deploy Large Language Models: A Practical Guide

    The core question is simple: is a more capable general-purpose large language model actually useful? It may sound subjective, but it is an engineering problem. “Useful” is not just a user-experience comment; it is a set of metrics that can be decomposed, measured, and reproduced. This article sets aside specific product attributes and frames the topic as capability evaluation and engineering deployment of a new generation of general-purpose large language models, offering a complete methodology and an actionable checklist.

    1. Break “Useful” into Measurable Dimensions

    The first pitfall many teams fall into is drawing conclusions from a few ad hoc prompts. A rigorous approach starts with a dimension framework:

    • Task completion: accuracy and usability on target scenarios such as ticket classification, summarization, code completion, and knowledge Q&A.
    • Instruction following: whether the model reliably obeys format constraints, length limits, role settings, and prohibited items.
    • Structured output: the validity rate and field completeness of machine-readable formats such as JSON and tables.
    • Long-context utilization: the ability to locate key information in long documents, reason across sections, and resist interference.
    • Stability and consistency: variance across repeated samples of the same input, and controllability after adjusting the temperature parameter.
    • Engineering cost: per-request latency, throughput, and the resource overhead introduced by context length.
    • Safety and compliance: interception of sensitive content, prevention of data leakage, and auditability.

    Only when these dimensions are made explicit can evaluation move from “feels good” to “achieves metric Y on dataset X.”

    2. Build Your Own Evaluation Set

    Public leaderboards are useful only for initial screening; what really drives selection is a private evaluation set. A size of 100–300 cases is recommended, covering the real distribution:

    1. Sample real requests: extract high-frequency and long-tail samples from (desensitized) production logs.
    2. Annotate golden answers: have business experts provide reference answers and scoring points.
    3. Add adversarial cases: include ambiguous questions, extremely long inputs, format traps, and privilege-escalation inducement.
    4. Design in layers: bucket cases by difficulty and scenario to pinpoint capability gaps.

    Illustrative structure:

    1. {
    2. "id": "case-0421",
    3. "scene": "knowledge_qa",
    4. "input": "...(desensitized real question)",
    5. "reference": "key points of the reference answer",
    6. "constraints": ["output no more than 120 words", "must cite the supporting passage"],
    7. "tags": ["long_context", "format_strict"]
    8. }

    3. Define Metrics and Decision Rules Up Front

    The easiest way for evaluation to go off the rails is to change the standard while looking at results. A combination of three judging methods is recommended:

    • Automatic metrics: accuracy, field validity rate, format compliance rate, and citation hit rate.
    • Model-assisted review: use another model to score against the scoring points, after manual calibration first.
    • Manual spot checks: have two people blindly review disputed cases and compute agreement.

    Example decision rules:

    1. PASS: accuracy >= baseline + 5%, AND format validity >= 99%, AND P95 latency <= target threshold
    2. REVIEW: metrics on par but cost drops significantly -> enter small-traffic canary
    3. FAIL: any hard constraint (safety, format) not met

    4. Look Beyond Quality: Inference Cost and Architecture Constraints

    Quality gains often come with larger context lengths and expanded sampling parameters, and cost does not scale linearly. Engineering should focus on:

    • Context budget: fold the system prompt, retrieved snippets, and conversation history into a unified token budget, trimming by relevance when the limit is exceeded.
    • Caching strategy: apply prefix caching to high-frequency prefixes (system prompts, fixed knowledge blocks) to reduce repeated computation.
    • Batching and concurrency: route offline tasks through batch throughput, and keep P95 latency for online tasks.
    • Fallback path: automatically switch to a smaller-parameter model or rule-based fallback when the primary path exceeds the threshold.

    Pseudocode illustration:

    1. def call_model(prompt, ctx_budget=6000):
    2. payload = trim_to_budget(prompt, ctx_budget)
    3. resp = llm.generate(payload, temperature=0.2, max_tokens=512)
    4. if not validate_schema(resp):
    5. resp = llm.generate(payload, temperature=0.0) # strict-mode retry
    6. return resp

    5. Structured Output and Controllability Engineering

    In enterprise scenarios, “can chat” is not the same as “can be integrated into a system.” Key points include:

    • Constrained decoding / schema validation: define the schema first, then validate; retry or fall back on failure.
    • Low temperature + fixed random seed (if the platform supports it) to improve reproducibility.
    • Layered prompts: put rules in the system layer and data in the user layer to prevent rules from being polluted by input.
    • Tool-call boundaries: the model only outputs the call intent; the backend performs the actual permission checks and execution.
    1. schema = {"type":"object","required":["label","confidence","evidence"]}
    2. obj = parse_json(resp, schema)
    3. if obj is None:
    4. return fallback_rule_based(input_text)

    6. Rollout Path: Canary, Observability, Rollback

    1. Shadow traffic: run the new model in parallel with production, logging only without taking effect, and compare differences.
    2. Small-traffic canary: ramp up by user or request proportion, with automatic circuit-breaker metrics defined.
    3. Observability: retain logs of input/output summaries, latency, token usage, and failure reasons; combine monitoring alerts with a logging service to close the loop.
    4. Rollback plan: keep the previous version’s configuration and switch back with one click when metrics degrade.

    7. Common Pitfalls

    • Replacing a private evaluation with public leaderboards;
    • Testing only “smart” questions, not format and safety hard constraints;
    • Ignoring information loss and interference under long context;
    • Treating prompts as a one-time asset, lacking version management and regression testing;
    • Evaluating cost by unit price alone, ignoring the amplification from retries and overly long inputs.

    Conclusion

    The most reliable way to answer “is it useful” is not to listen to conclusions but to build your own measurement system: define the dimensions, build a private evaluation set, fix the decision rules, put cost and stability into the same table, and then use canary rollout and observability to ensure a safe launch. On top of standard engineering components such as the general-purpose model services, container platform, object storage, logging service, and monitoring alerts offered by Baidu AI Cloud, this methodology can be reused directly, moving model selection from subjective impression to a verifiable, rollback-capable engineering decision.