Practical Prompt Engineering for Large Language Models: Designing Effective Instructions Across Scenarios

    This article explains how to craft high-quality prompts for large language models, covering the five essential elements of structured prompts, model selection based on task complexity, and detailed instruction templates for five typical use cases—slide decks, financial models, code review, game prototypes, and mechanical design. It also outlines output verification practices and common pitfalls to avoid, helping practitioners improve output accuracy and reliability.

    Why Prompt Quality Determines Output Quality

    The quality of a large language model’s output largely depends on how complete and explicit the input is. When instructions are vague, the model fills in background and assumptions on its own, often leading to results that drift from actual needs. The core task of prompt writing is to clearly state the objective, constraints, input material, and output format, so the model works within well-defined boundaries.

    Five Elements of Structured Prompts

    1. Role and Goal – specify the role the model should adopt and the outcome you expect.
    2. Background and Input – provide the context, data, or code snippets, and mark which information is known.
    3. Constraints – list technical stack, versions, accuracy requirements, length limits, and prohibitions.
    4. Processing Steps – ask the model to list assumptions first, then propose solutions, and finally self-check. Step-by-step processing reduces jumping errors.
    5. Output Format – specify structure such as tables, sections, or code blocks for easier reading and comparison.

    A general template looks like this:

    1. [Role] You are a backend engineer with five years of experience, familiar with relational databases and API design.
    2. [Background] ... (requirement description or code snippet)
    3. [Constraints] 1. Do not introduce new third-party dependencies; 2. Keep the existing interface signature unchanged.
    4. [Steps] First list your assumptions, then provide the solution, and finally check each constraint.
    5. [Output] Return a table with columns: issue ID, location, severity, reason, and suggested fix.

    Choosing the Right Model Based on Task Complexity

    Different models vary in reasoning depth, response speed, and cost. Model selection can be guided by task difficulty:

    • Complex tasks – multi-module architecture design, cross-disciplinary engineering analysis, long-chain financial reasoning. These require strong reasoning power and can tolerate slower responses.
    • Everyday tasks – copy rewriting, format conversion, single-file code review, meeting notes. Speed and cost matter more here; a fast-responding model is usually sufficient.

    Selection decisions should be based on actual testing. Run the same set of test samples across candidate models, record accuracy, latency, and cost, and then decide how to divide the workload. Do not rely only on marketing materials.

    Instruction Design for Typical Scenarios

    4.1 Slide Deck Creation

    This scenario aims to produce an outline that can be further refined. The prompt should include the audience, duration, slide count, and the key conclusion.

    1. Audience: mid-level managers; duration: 15 minutes; 12 pages.
    2. Topic: Q3/Q4 channel expansion plan for the East China region.
    3. Key conclusion: prioritize two high-growth cities, invest the budget in two stages.
    4. Requirement: for each page, output a page title, three to five bullet points (each no more than 20 characters), and a speaking note.

    Limiting bullet length keeps the layout clean. Requiring speaking notes allows the outline to be used directly for rehearsal.

    4.2 Financial Model Construction

    For financial scenarios, assumption transparency is critical. The model should first list all assumptions, then build the calculation structure, and finally provide sensitivity analysis.

    1. Build a three-year cash flow forecast.
    2. Known: opening cash $5 million; monthly revenue growth 3%; gross margin 42%; fixed costs $800,000 per month.
    3. Requirements:
    4. 1. First list all assumptions, and mark which ones are your inferences.
    5. 2. Output revenue, costs, expenses, and cash balance on a monthly basis.
    6. 3. Show the change in ending cash balance when revenue growth is 1%, 3%, and 5%.

    Models may make arithmetic errors in multi-step calculations, so key numbers must be manually rechecked. Use spreadsheet software or scripts to verify the results.

    4.3 Code Review

    Code review prompts should define the review dimensions and require issues to be sorted by severity. Here is a code snippet to review:

    1. def get_user(conn, name):
    2. sql = "SELECT * FROM users WHERE name = '" + name + "'"
    3. return conn.execute(sql)

    The prompt can be written as:

    1. Review the function above. Check dimensions: security, boundary conditions, error handling.
    2. List issues in descending order of severity, and provide fixed code examples for each issue.

    The model should identify that string concatenation may lead to injection risks and recommend parameterized queries. Review conclusions still need developer confirmation, especially for logic involving permissions and financial operations.

    4.4 3D Game Prototype Development

    Game prototypes are best developed module by module. Start with module interfaces and data structures, then implement modules one by one, and finally generate test cases. A recommended breakdown is:

    1. Scene and resource loading
    2. Character movement and input handling
    3. Collision detection and interaction logic
    4. UI and state management

    Each prompt should include the interface definitions from the previous step to avoid naming inconsistencies. The generated code must be run in the target development environment and corrected based on runtime results.

    4.5 Mechanical Design and Engineering Simulation Assistance

    In mechanical design scenarios, models are suitable for early-stage work such as concept generation, structural descriptions, assembly relationship mapping, and simulation workflow planning.

    1. Design three bracket structure options for a device carrying 200 kg.
    2. For each option, compare: weight estimate, stiffness characteristics, manufacturing difficulty, and assembly steps.
    3. Mark the critical load cases that need simulation verification.

    Model-generated designs cannot go directly to production. Material strength, tolerances, assembly precision, and fatigue life must be verified by professional engineers based on relevant standards and measured data. Values from the model serve only as starting points.

    Output Verification Mechanism

    • Fact checking: verify numbers, formulas, and referenced standards or literature item by item.
    • Practical validation: run code through tests; recompute arithmetic with scripts or spreadsheets.
    • Tiered sign-off: creative and copy-based results can be adopted quickly; financial, engineering, and safety-related results require confirmation by qualified personnel.
    • Record keeping: save prompts, model versions, and outputs together for review and traceability.

    Common Pitfalls

    • Submitting too many tasks at once. The more tasks, the higher the chance of omissions. Break tasks into smaller, focused prompts.
    • Ignoring model constraints and assuming infinite context or reasoning capability.
    • Forgetting to specify the output structure, leading to unstructured or hard-to-parse responses.
    • Treating model outputs as final without human review, especially in high-stakes domains.