Practical Ways to Use Large Language Models: Engineering Best Practices

    This article explains how to use large language models (LLMs) effectively in real projects, focusing on their capability boundaries, four high-frequency use cases, prompt and context design, and evaluation and governance. It shows why LLMs should generate candidate answers rather than serve as the final source of truth, how to inject external knowledge through retrieval, and how to combine interactive refinement with deterministic validation for reliable results in Q&A, content production, code work, and translation.

    1. Start With the “Search Engine” Mindset: Define the Capability Boundary

    For many people, the first impression of a large language model is that “asking questions feels smoother than searching”: instead of picking through a list of links, you get a ready-made explanation, and if it is not good enough, you can follow up and ask the model to rephrase it or change the level of detail. This multi-turn interaction is indeed closer to how people communicate than traditional retrieval. But it also brings a realization you need to establish early: the model’s output is probabilistically generated text, not verified fact.

    A more reliable way to position the model is as an “assistant that quickly produces candidate answers,” not as the “final source of truth.” Anything involving version numbers, time-sensitive data, prices, regulations, or specific API signatures should be double-checked against authoritative sources. A more dependable engineering approach is to inject external knowledge into the context through retrieval, let the model handle summarization and expression, and leave “memory” to a knowledge base that can be updated and audited. Example code:

    1. def answer_with_context(question, retriever, llm):
    2. docs = retriever.search(question, top_k=5) # Retrieve up-to-date material
    3. context = "\n\n".join(f"[{i+1}] {d.text}" for i, d in enumerate(docs))
    4. prompt = f"""Answer the question based only on the material below, and mark the citation number at the end of each sentence;
    5. If the material is insufficient, explicitly state "not covered by the material" and do not speculate.
    6. Material:
    7. {context}
    8. Question: {question}"""
    9. return llm.generate(prompt)

    2. Four High-Frequency Use Cases and Their Engineering Focus

    2.1 Interactive Q&A and Concept Clarification

    The value is not in “knowing the answer” but in being able to converge step by step by adding constraints: first ask for a definition, then a comparison, then boundary conditions and counterexamples. To make the answer usable, explicitly state the role, audience, and output structure in the prompt, for example: “For backend developers with two years of experience, explain in three paragraphs and list three common misconceptions at the end.” Adjusting tone, dialect, and formality belongs to the same category of techniques—using style constraints to fit the output to the scenario—but this only affects expression and does not improve factual reliability.

    2.2 Content Production Assistance

    Topic selection, outlines, title candidates, paragraph rewriting, and long-text compression are among the scenarios with the highest return on investment. The key practice is to break “creation” into verifiable small steps: first generate an outline and confirm it manually, then expand section by section, and finally unify terminology and style. When generating titles in bulk, you can ask the model to output structured results that are easy for a program to consume:

    1. {"titles": [
    2. {"text": "Candidate title one", "angle": "problem perspective", "length": 22},
    3. {"text": "Candidate title two", "angle": "solution perspective", "length": 20}
    4. ]}

    2.3 Code Understanding, Generation, and Refactoring

    Models are good at explaining unfamiliar code, adding tests, suggesting refactoring ideas, and turning pseudocode into an implementation; what they are not good at is confirming dependency versions and runtime environments for you. A reliable workflow is “generate in small steps + verify immediately”: have the model output a minimal runnable snippet, backed by unit tests and static checks; changes involving concurrency, transactions, or permissions must be reviewed manually. A practical pattern is to have the model first produce a list of changes and risks, then produce the patch.

    2.4 Translation and Terminology Consistency

    The difficulty of technical translation lies in consistent terminology and not breaking code. The approach is to first extract a glossary and fix the translations, then translate section by section, and finally do a review that “only checks terminology and the integrity of code blocks.” Explicitly stating in the prompt “do not translate identifiers, do not modify the example code” can significantly reduce rework.

    3. Prompts and Context: Pushing Down Uncertainty

    • Structured instructions: a four-part structure of role, input, constraints, and output format reduces ambiguity.
    • Give examples rather than adjectives: one or two input-output examples are far more effective than “write more professionally.”
    • Layer the context: pass system constraints, long-term background, and the current material separately to avoid cross-contamination.
    • Long context is not free: the longer the content, the higher the chance that key information is diluted, so filter first and then concatenate.
    • Adjust the temperature parameter by task: use low temperature for extraction and classification, and a higher temperature for creative divergence.

    4. From “Usable” to “Deliverable”: Evaluation and Governance

    Once you connect a model to a business, what really determines success is the closed loop. It is advisable to build a small-scale evaluation set (including boundary and adversarial samples) and continuously observe accuracy, format compliance rate, citation coverage, latency, and cost; apply schema validation and sensitive-content filtering to outputs; and feed failed samples back as input for improving prompts and the knowledge base. Logging and monitoring can reuse common capabilities, such as log services, monitoring and alerting, object storage, and message queues, used to retain samples, perform asynchronous review, and link alerts.

    For multi-user scenarios, you also need session isolation and access control at the application layer to ensure that different users’ conversation data is not visible to each other; the model side should only process the necessary context, and sensitive fields should be masked before entering the model. If you have requirements for data residency and compliance, you can combine the general cloud product capabilities of Baidu AI Cloud to complete the routine design of deployment, storage, and auditing.

    5. Common Misconceptions

    1. Treating fluency as correctness: high language quality does not mean the facts hold.
    2. One-shot long prompts: the more constraints, the more likely they conflict, so they should be given step by step.
    3. Ignoring reproducibility: fixing randomness and recording prompts and versions is the only way to regress issues.
    4. Letting the model make permission decisions: authorization and validation must be done by deterministic code.

    6. Summary

    The benefits of large language models come from the combination of “interactive convergence + external knowledge injection + deterministic validation.” Put the model in the right place—responsible for understanding and expression—and leave facts, permissions, and consistency to engineering means, and you can stably produce usable results across the four scenarios of content, code, translation, and Q&A.