Selecting, Prompting, and Customizing Large Language Models for Production

    A practical framework for evaluating large language models by task, cost, and risk, then putting them into production with prompt design, RAG, tool calling, targeted fine-tuning, and engineering controls.

    Stop Asking Which Model Is Best

    “Which mainstream LLM is best?” is rarely a reusable answer. Quality depends on task type, context length, output format, latency, budget, data sensitivity, and the existing engineering stack. The same model can perform very differently on short-form scripts, contract extraction, code repair, and enterprise knowledge Q&A. With different prompts, retrieval quality, tool use, and fine-tuning data, results can also differ by an order of magnitude.

    Ask better questions:

    1. What is the core task, and how is success measured?
    2. Does the work depend more on language understanding, reasoning, code generation, multimodal generation, voice interaction, or long-context retrieval?
    3. What are the requirements for latency, concurrency, reliability, cost, private deployment, and audit?
    4. What engineering skills does the team have—fine-tuning, RAG, tool calling, or on-prem inference?
    5. When the model is wrong, can human review, rule checks, or rollback contain the damage?

    Selection should not stop at brand comparison. Build an evaluation frame around scenario, capability, cost, and risk.

    A Five-Dimension Evaluation Frame

    Split evaluation into five dimensions and set weights before a PoC. Weights should follow business risk. Customer support should emphasize grounded answers and compliance; coding assistants should emphasize correctness, executability, and context; content creation should emphasize style control and multimodal ability.

    Dimension Key questions Example metrics Typical weight
    Task quality Can it complete the core job reliably? Task success rate, human-edit time, valid structured-output rate, citation hit rate 30%–45%
    Stability and control Is output consistent, checkable, and reversible? Run-to-run consistency, policy-violation rate, tool-call success, retry rate 15%–25%
    Engineering performance Can it meet production experience? Time to first token, end-to-end latency, throughput, long-context stability 10%–20%
    Cost and resources Is unit cost of a successful task acceptable? Cost per successful task, average output length, cache hit rate, resource use 10%–20%
    Compliance and security Does it meet data, audit, and content-safety needs? Sensitive-data hit rate, audit coverage, isolation, access-control completeness 10%–25%

    Use a weighted score, but do not rely on averages alone. Define veto items: data must stay in-region, answers must cite sources, code must pass tests, high-risk content must be human-reviewed. Fail a veto item and the candidate should not go to production.

    Capability Profiles Instead of Brand Rankings

    Do not treat brand names as conclusions. Compare candidates on the same evaluation set with verifiable results, not marketing or a single demo.

    Low-latency multimodal interaction

    These capabilities emphasize speed, voice, image/video generation, mobile experience, and agent entry points. They fit daily companionship, speaking practice, short-video scripts, marketing copy, light office help, and lifestyle queries.

    Strengths: natural interaction, low barrier, broad basics. Weaknesses: long-conversation memory, multi-step reasoning, academic accuracy, and domain depth. For content, add fact checks, copyright checks, and brand rules. For speaking practice, define correction granularity and privacy bounds. For light office work, use templates and second-pass validation to reduce hallucination.

    Use first for low-risk, high-frequency, highly interactive work. For money, legal, medical, or contract content, require a knowledge base, rule checks, and human review.

    Enterprise compliance and vertical customization

    These capabilities emphasize private deployment, permission isolation, audit logs, content safety, fine-tuning, multimodal generation, and cloud integration. They fit enterprise office work, commerce, vertical model development, BI analysis, and multimodal production.

    Strengths: governance, integration, customization. Weaknesses can include weaker consumer UX, limited free quotas, slower responses, thinner community, and higher customization/ops cost. Verify data isolation, fine-grained permissions, audit records, version rollback, fine-tune data management, and elastic inference.

    Map the business process before deciding to fine-tune. Most knowledge Q&A and workflow assistants should start with RAG + tool calling + output validation, not training a model first.

    Reasoning, code, and research

    These capabilities emphasize logic, math, code generation, commercially usable open weights, distillation, and local deployment. They fit development, research, reasoning tasks, specialist Q&A, and on-device inference.

    Strengths: harder reasoning and coding; some models can be quantized, distilled, or PEFT-tuned to cut cost. Weaknesses: weaker casual chat, weaker multimodal, weaker colloquial understanding, higher skill barrier. For code, require compile, unit tests, static analysis, and review—not “looks like code.” For research, require a checkable reasoning summary and sources so fluency is not mistaken for truth.

    Build a sandbox. All generated code must be tested and reviewed. Local deployment must count hardware, ops, upgrades, and security patches—not only one-time setup.

    General balanced models

    There are also balanced models for Q&A, generation, summarization, and light tool use. They are rarely best at one thing, but APIs are stable and coverage is broad—useful for MVPs and cross-team assistants. Check long-context stability, structured-output validity, tool reliability, and cost curves so a good demo does not become an uncontrollable production system.

    Let a Gold Evaluation Set Decide

    Without a test set, selection becomes taste. In PoC, build 50–200 representative tasks covering high-frequency, long-tail, edge, and high-risk cases. Each sample should include input, context, expected output, judging criteria, risk labels, and reference sources.

    Suggested metrics:

    • Task success: usable as-is or with light edits
    • Structured-output validity: fields, types, enums, required items
    • Groundedness: answers trace to retrieved snippets or business data
    • Consistency across repeated runs
    • Safety and privilege violations
    • Engineering: first-token latency, E2E latency, failure and retry rates, throughput
    • Economics: cost per success, output length, cache hits, human-review cost

    Run PoC in three steps:

    1. Offline eval on a fixed set; record version, prompt, parameters, and raw output.
    2. Shadow traffic on real requests without affecting users.
    3. Small A/B on low-risk users or tasks, with rollback thresholds and human review.

    Define exit conditions: invalid structured output below threshold, persistently low citation hits, latency beyond SLA, or a leak/privilege incident—then degrade or roll back.

    Prompts Are Interface Design, Not Spells

    A gold prompt structure

    Use role + task + background + constraints + output format + quality check. Treat the model as an API contract so you can validate and iterate.

    1. Role: You are a senior engineer/analyst/editor in [domain].
    2. Task: Complete [specific task] for [business purpose].
    3. Background: Known information includes [context/data/constraints]. Do not invent unknowns.
    4. Constraints:
    5. 1. Follow [business/safety/format rules].
    6. 2. If uncertain, output “need more information” and list missing fields.
    7. 3. Do not output content outside authorized scope.
    8. Output format:
    9. - Conclusion: no more than 120 words
    10. - Evidence: list traceable sources item by item
    11. - Risks: list likely error points
    12. - Next actions: 1–3 executable suggestions
    13. Quality check:
    14. Before responding, verify complete fields, traceable facts, no sensitive data, no privilege overreach.

    Write quality requirements into the prompt, then still validate in software. Prompts do not replace permissions, redaction, output filters, or human review.

    Decompose complex work

    Do not ask the model to finish everything in one shot. Build a task graph with intermediate artifacts and checkpoints—for a business report: clarify requirements → confirm metric definitions → retrieve data → draft → fact-check → format → human review.

    Store inputs, outputs, model version, prompt version, and validation results so you can tell retrieval error from prompt ambiguity, model limits, or rule changes.

    Context engineering beats dumping long context

    Long context is not effective context.

    • Summarize history; keep decisions, constraints, and open items.
    • Chunk retrieval; keep titles, sources, timestamps, and permission tags.
    • State that materials are references and newer business rules win on conflict.
    • Require source snippets; lower confidence if none exist.
    • Maintain a state table for multi-turn work instead of concatenating all history.

    Structured output and automatic validation

    Anything that enters a business system should be structured and field-checked. Tickets need category, priority, suggested action, and sources. Contract extraction needs fields, confidence, and original spans. Invalid output should retry, fall back to a template, or go to a human—not write to production.

    Tool calling: few and precise

    Least privilege: expose only required APIs, validate parameters, audit results. Writes should preview, confirm, then execute. Reads should limit scope and fields. A business gateway should re-check model-generated parameters to prevent overreach.

    From Prompts to Customization: Smallest Necessary Change

    Priority order

    Prompt optimization → RAG → tool calling → parameter-efficient fine-tuning → distillation or continued pretraining. Most problems do not need training from scratch. Prompts fix expression and format; RAG fixes freshness and traceability; tools fix computation and operations; fine-tuning fixes style, terminology, and hard instruction following.

    Fine-tune data

    Quality, representativeness, and evaluability beat volume.

    • Clear labeling rules; one answer policy per question
    • Deduplicate, redact, drop low-quality and conflicting samples
    • Cover high-frequency, long-tail, edge, and refusal cases
    • Train/val/test split; the test set must not drive tuning
    • Keep negatives and “I don’t know” samples
    • Record source, authorization, and version for audit

    Deployment and cost

    Private deployment must account for inference resources, concurrency, autoscaling, cache, monitoring, and upgrades. Cost levers: shorter outputs, result cache, routing by task size, batching non-real-time work, quantized models for non-critical paths, human review for high risk.

    Cheap inference is not low TCO. After deploy you still pay for data governance, logs, alerts, upgrades, patches, and people. Compute total cost per successful task, not list price per call.

    Reuse an existing cloud base

    If the organization already uses Baidu AI Cloud, object storage, logging, monitoring, and containers can form the data and runtime layer. Model capability should still pass an internal eval set and small-traffic tests before scale-up. Product scope, SLAs, and billing should follow official documentation and actual tests—not informal promises.

    Engineering Governance: From Demo to Production

    Unified access layer

    Sit an access layer between apps and models for auth, rate limits, retries, routing, degradation, audit, and cost. Switch models, gray-release, or roll back without changing business code. Log prompt version, model version, retrieved snippets, tool parameters, and validation results.

    Versioning

    Version prompts, retrieval policy, fine-tune data, and models. Run regression evals before release. Gray-release high-risk work with human review; do not cut over 100% at once.

    Observability

    Monitor volume, success rate, first-token and E2E latency, output length, structured-output validity, tool success, retrieval hit rate, human-edit rate, safety blocks, and cost per success. Do not store sensitive data in plaintext logs; use redaction, summaries, or hashes.

    Security and compliance

    Threats include prompt injection, poisoned retrieval, privilege abuse, leaks, and unsafe output. Defense in layers:

    • Input: classification, redaction, injection and sensitive-term detection
    • Retrieval: permission filters, source trust, freshness
    • Generation: system constraints, output filters, structured checks
    • Execution: least-privilege tools, write confirmation, sandbox
    • Operations: audit, alerts, human review, emergency rollback

    Scenario Guidance

    Daily interaction and content

    Prioritize latency, multimodal, natural voice, and templates. Fit for short-video scripts, marketing copy, speaking practice, light office help. Add brand glossaries, fact checks, copyright checks, and content filters. Do not publish unverified generation.

    Enterprise knowledge Q&A and office assistants

    Prioritize access control, RAG, citations, audit, and private deployment. Knowledge-base quality often matters more than the model: parsing, chunking, metadata, permission tags, and updates. Answers should cite sources; otherwise refuse or escalate.

    Code and reasoning

    Prioritize correctness, long context, tools, and executable checks. Require compile, tests, static analysis, and review. Use a generate–execute–test–fix loop; do not paste model output into production.

    High-volume support and tickets

    Prioritize cost per success, structured validity, latency, and degradation. Route simple high-frequency issues to smaller models, hard cases to stronger models, and remainder to humans. Refunds, complaints, and account security need extra confirmation and permission checks.

    Vertical specialist Q&A

    Prioritize terminology, freshness, citations, and safety bounds. Prove RAG first, then consider fine-tuning. Domain experts should label data. Keep regression tests so new rules do not produce stale answers.

    Go-Live Checklist

    1. Core tasks and measurable success criteria defined?
    2. Eval set covering high-frequency, long-tail, edge, and high-risk cases?
    3. Compared success rate, latency, unit cost, and human-edit rate?
    4. Validated structured output and tool reliability?
    5. Data classification, redaction, permissions, and audit specified?
    6. RAG, citations, and refusal designed?
    7. Prompts, retrieval, and tools tried before fine-tuning?
    8. Gray release, monitoring, degradation, and rollback in place?
    9. Human review for code, money, contracts, medical, and legal output?
    10. Total cost including ops, data, and review calculated?

    Conclusion

    There is no scenario-free “best” LLM. Split the business problem into evaluable tasks, compare capability profiles on one test set, then close the loop with prompts, RAG, tools, necessary fine-tuning, and governance. Low-risk high-frequency work can chase experience and speed; enterprise work should put compliance, traceability, and operability first; code and reasoning should insist on sandboxes and tests; vertical domains should fix knowledge quality before customizing models.

    The goal is not picking one model. It is a system you can iterate: tasks measurable, outputs checkable, costs accountable, risks controlled, versions reversible. Only then can you honestly answer whether a model is “good enough.”