Large model development: Prompt word engineering from entry to mastery

Written by
Caleb Hayes
Updated on:June-21st-2025
Recommendation

Master the prompt word engineering to comprehensively improve the quality and efficiency of large model output.

Core content:
1. The foundation and value of prompt engineering
2. Prompt design process and three elements
3. Detailed explanation of the three paradigms and practical cases

Yang Fangxian
Founder of 53A/Most Valuable Expert of Tencent Cloud (TVP)
Prompt engineering is the basic skill of large model development. This article will systematically introduce Prompt engineering from five aspects: principle explanation, design process, optimization ideas and case practice, to help you fully master the whole process of prompt design.

Table of contents

  1. Getting Started: Prompt Engineering Basics

  2. Design: Prompt composition and process

  3. Practical Chapter: Detailed Explanation and Examples of the Three Paradigms

  • Zero-shot

  • Few-shot

  • Chain-of-Thought

  • Optimization: Tuning ideas and techniques

  • Advanced: Templating, Automation, and Toolchains

  • Case Study: Five Typical Cases


  • 1. Getting Started: Prompt Engineering Basics
    What is Prompt Project?
    Prompt Engineering is a systematic method for designing, writing, and optimizing input prompts for large language models (LLMs), with the goal of guiding the model to produce expected outputs. It is similar to "giving instructions" to the model, using clever language expressions to make the model "understand" the task.
    The value of the prompt word:
    • Improve output quality : reduce ambiguity, control style, and improve accuracy

    • Expanded application scenarios : covering writing, translation, code generation, knowledge question answering, etc.

    • Reduce costs : reduce repeated fine-tuning and reduce the number of API calls


    2. Design: Prompt composition and process
    2.1 Three Elements of Prompt
    1. Instructions : clearly state “what to do” (e.g. “Please translate the following text into English”)
    2. Context : Provide necessary information (such as original text, background, format requirements)
    3. Output constraints : format, length, style, tone, etc. (e.g. "no more than 100 words", "in the form of a press release")

    2.2 Design Process
    1. Clarify the goal: first write a "natural language" version of the requirement
    2. Breaking down the elements: separating the task description, context, and constraints
    3. First version writing: splicing the three elements into a complete prompt
    4. Test verification: call the model, observe the output, and record the problem
    5. Iterative optimization: adjust instructions, add and delete examples, and fine-tune the format
    6. Encapsulation and reuse : template mature prompts and output documents or scripts

    3. Practical application: detailed explanation and examples of the three paradigms
    3.1 Zero-shot
    Features: No examples are provided, instructions are given directly

    Example: Text Sentiment Analysis

    Instruction: Please judge the sentiment of the following review and output "positive", "neutral" or "negative": Comment: I really liked this movie, but the ending was a bit hasty.
    • Output constraint: only output one of the three labels

    • Optimization idea: You can add "briefly explain the reason"


    3.2 Few-shot
    Features: Provides a small number of input-output pairs to help models "align"

    Example: English synonymous sentence rewriting

    Here are some examples of original sentences and their rewrites:Example  1 :Original sentence: The  weather  is  nice today.Rewrite: Today 's weather  is  pleasant.
    Example  2 :Original sentence: She  completed the task quickly.Rewrite: She  finished the task  in  no time.
    Please rewrite the following sentences with synonyms:Original sentence: He  solved the problem efficiently.rewrite:
    • Number of examples: Typically 2–5

    • Note: Examples should be diverse and cover edge cases


    3.3 Chain-of-Thought
    Features: Guides the model to think step by step, suitable for complex reasoning or calculation

    Example: Math Problem Step-by-Step Solution

    Please analyze and answer the following question step by step: "Xiao Ming has 12 apples. After sharing them among 3 friends, how many apples does each get?" Thinking process: 1. Total number of apples... 2. How much each person gets = total number ÷ number of friends... Answer:
    • Effect: Significantly improve the accuracy of multi-step reasoning

    • Extension: It can be used for logical reasoning in fields such as law and medicine.


    4. Optimization: Tuning ideas and techniques
    • Clarify role settings
    "You are an experienced lawyer. Please analyze the following contract terms using professional terms:..."
    • Control output length
    “Please summarize the following in no more than 50 words:…”
    • Multi-tasking mix
    "Please translate first, then give five key words, and then refine the summary."
    • Error correction and self-checking

    To guide the model to self-check:

    “Please check the above answers for inconsistencies or errors and provide suggestions for revisions.”
    • Temperature and Top-k parameter tuning
    • Low temperature (0.0–0.3): output is more stable and controllable
    • High temperature (0.7–1.0): More creative

    5. Advanced: Templating, Automation, and Toolchain
    • Prompt Template Library : Write common prompts into configurable templates (such as JSON + Mustache)

    • Prompt Chaining : Connect multiple prompts in series to form a pipeline

    • Automation platform : management and monitoring using LangChain, PromptLayer, LlamaIndex, etc.

    • Evaluation and measurement : Building an automated evaluation system (BLEU, ROUGE, manual scoring, etc.)


    6. Practical Case Studies
    Serial number
    Scenario
    type
    Key points
    1
    Sentiment Analysis
    Zero-shot
    Directly judge the sentiment of the text, output the label and briefly explain it
    2
    Code Generation
    Few-shot
    Provide sample code—input-output pairs, specify language and functionality
    3
    Data visualization suggestions
    Chain-of-Thought
    Given a data description, guide the model to think step by step and output a visual chart design solution
    3
    Customer service chat robot
    Few-shot + Mixed
    Multi-turn dialogue example + context management, control response style
    4
    Medical diagnosis report summary
    Chain-of-Thought
    Extract key indicators step by step and generate structured reports

    Case 1: Text Sentiment Analysis (Zero-shot)
    Instructions: Please judge the sentiment of the following user comments and output "positive", "neutral" or "negative", and then briefly explain the basis for your judgment (no more than two sentences). Comment: The user experience of this product is very poor, and the customer service is unhelpful.
    Expected Output:
    Negative Judgment basis: The user explicitly stated that the experience was "very bad" and was dissatisfied with the customer service.

    Case 2: API Code Generation (Few-shot)
    The following is an example of Python calling the OpenAI interface: Example 1: Input: Call the text-davinci-003 model to generate a greeting Output: ```pythonimport openaiopenai.api_key = "YOUR_KEY"response = openai.Completion.create( model="text-davinci-003", prompt="Please generate a Chinese greeting.", max_tokens=20)print(response.choices[0].text.strip())
    Expected Output:

    Example  2 :Input: Call chat-gpt- 4  model to have a conversation  Output:```Pythonimport  openaiopenai.api_key =  "YOUR_KEY"response = openai.ChatCompletion.create(    model = "gpt-4" ,    messages=[        { "role" : "system" , "content" : "You are an assistant." },        { "role" : "user" , "content" : "What's the weather like today?" }    ])print (response.choices[ 0 ].message.content)
    Please write a piece of Python code according to the above style and use the OpenAI interface to generate a "simple weather forecast" text.

    Case 3: Data Visualization Design (Chain-of-Thought)
    Please refer to the following data description, think step by step and give three design solutions for visualization charts, including chart type, fields to be displayed, color matching and title suggestions.
    Data description:  -  Product sales: date (2025-01-01 to 2025-04-30), sales, product category (A/B/C), region (East China/South China/North China)
    Require:1.  Think about the applicable scenarios, advantages and disadvantages of each chart step by step;  2.  Finally output the specific design points of three charts.  

    Case 4: Multi-round customer service conversation (Few-shot + mixed)
    You are an online customer service robot with a professional and friendly style. The following are two rounds of sample conversations:
    Example 1:User: I want to check the delivery status of order 12345.  Robot: Hello, I will check for you right away... Your order was shipped on May 12 and is expected to be delivered on May 15.
    Example 2:User: Can I change the delivery address?  Robot: Sure, please provide a new delivery address and I will help you modify it.
    Please continue the next round of dialogue with the user:User: My delivery address has been changed from Haidian District, Beijing to Jing'an District, Shanghai.

    Case 5: Medical Diagnosis Report Summary (Chain-of-Thought)
    Scenario: The doctor has provided the patient's examination data and now needs to generate a structured diagnosis report.
    Check the data:  - Blood pressure: 135/85 mmHg  - Blood sugar (fasting): 6.2 mmol/L  - Heart rate: 78 beats/min  - Cholesterol: total cholesterol 5.8 mmol/L, HDL 1.2, LDL 3.4
    Prompt:Please first analyze the normal range of each indicator step by step and whether there is any deviation; then give diagnostic points such as "high blood pressure", "high blood sugar", "normal heart rate", "high blood lipids" based on the analysis; finally, integrate them into a diagnostic report of no more than 150 words.

    OK, the above is the tutorial of Prompt Prompt Engineering from entry to mastery. By understanding the basic theory, mastering the design process, and repeated practical iterations, you will be able to control large models and provide high-quality solutions for various needs. I hope it helps you~~~