A practical guide to prompting engineering: from Zero-Shot to Graph Prompting, a complete analysis of 7 core technologies

Master the efficient use of large language models and gain an in-depth understanding of the seven core technologies of prompt engineering.
Core content:
1. The simplicity and efficiency of zero-shot prompts and their application scenarios
2. The contextual learning ability and example design of few-shot prompts
3. Application examples and optimization strategies of prompt engineering in actual tasks
introduction
With the development of large language models (LLMs), prompt engineering has become a key skill to effectively use these models. Different prompting techniques are suitable for different scenarios. This article will introduce seven major prompting optimization modes and analyze their applicable scenarios and advantages and disadvantages.
Zero-Shot Prompting
Zero-shot prompts are as simple and natural as asking a friend "check the weather for me" without any examples. As long as you express your needs clearly, AI can take action immediately based on its existing knowledge. This method is not only simple and efficient, but also saves token space, and is particularly suitable for common text classification, simple question-answering, and content summarization tasks .
However, zero-sample prompts also have disadvantages, such as sometimes producing some hallucinations and limited performance when dealing with complex reasoning or professional tasks . To use it well, you need to use clear verb instructions (such as "classify", "summarize", "translate"), specify a clear output format (like JSON or Markdown), and add some constraints (such as word count) to achieve the best results. The clearer the instructions, the better the effect . Ambiguous prompts will confuse the AI and give less than ideal answers.
Example:
The core of zero-shot prompts is to use the model pre-training knowledge to directly complete the task without providing examples. The following is a zero-shot example of Weibo sentiment analysis:
Analyze the sentiment of the following microblogs and determine whether they are positive, negative, or neutral, and briefly explain why:
"Today I finally got the long-awaited new phone. The photo taking effect is amazing! Although it is expensive, it is totally worth it! #unboxing#newphone"
This example uses three key elements: clear instructions (analyzing sentiment tendencies), specific tasks (determining the sentiment of Weibo posts), and output constraints (providing sentiment labels and reasons). This allows the model to understand the task requirements and give structured answers without the need for examples.
Few-Shot Prompting
Figure: Few-Shot Prompting Example (Source: Prompt Engineering Guide [1] )
Few-shot prompts allow AI to understand the task by providing a few "examples", just like teaching a friend a new game by playing a few rounds for him. It uses the model's contextual learning ability, and only 3-5 carefully designed examples are needed to allow the model to draw inferences and handle new problems. This method does not require retraining the model, but can clearly convey expectations, improve performance in unfamiliar fields, and ensure consistent output formats. It is particularly suitable for tasks that require specific output formats, professional fields, or custom classification systems . However, it is highly sensitive to example quality, prone to "label bias" , and the number of examples is limited. When used, examples should cover major variants, keep the format consistent, ensure discrimination, and can be used in conjunction with CoT for complex tasks.
Example:
Based on the product features, generate attractive advertising slogans for the following products, with a length of 20-30 words:
[Example 1]
Product: A pair of noise-canceling headphones
Features: Active noise reduction, 30 hours of battery life, comfortable to wear
Slogan: Enjoy the world of music quietly, 30 hours of long battery life, and comfortable noise reduction just for focused listening.
Example 2
Product: Organic vegetable delivery service
Features: Picked on the same day, no pesticides, delivered to your home
Slogan: From farm to table, fresh organic vegetables, picked the same day and delivered to your home.
Example 3
Product: Smart Home System
Features: voice control, remote control, energy saving and environmental protection
Slogan: Smart voice control as you wish, remote control of a warm home, technology makes life more energy-efficient.
【New question】
Product: Sunscreen
Features: SPF50+, waterproof, refreshing and non-greasy
Advertising slogan:
Chain-of-Thought (CoT) Prompting
Figure: Chain-of-Thought Prompting Framework (Source: Wei et al. 2022 [2] )
The thought chain prompt guides the model to demonstrate the complete reasoning process by breaking down complex problems into continuous intermediate steps , utilizing the reasoning ability of the language model rather than simple memory , and reducing error accumulation through explicit reasoning , thereby significantly improving the model's performance on reasoning tasks.
Chain-of-Thought Prompting is particularly suitable for mathematical problems, multi-step logical reasoning, and tasks that require explaining the source of the answer . It significantly improves the performance of the model on complex reasoning tasks by showing the step-by-step reasoning process , and is ideal for symbolic reasoning and planning problems. It is worth noting that CoT shows obvious sensitivity to model size and is one of the "emergent capabilities" of large language models. However, CoT may produce seemingly reasonable but actually wrong reasoning chains . For particularly complex problems, more structured guidance may be required, and its effect is limited by the reasoning ability of the underlying model.
Example:
Question: A rectangle is 5 cm longer than it is wide, and its perimeter is 38 cm. Find the area of this rectangle.
Thought Process:
1. If the width is x centimeters, then the length is x+5 centimeters.
2. Perimeter formula: 2×(length + width) = 38
3. Substitute: 2×(x + x + 5) = 38
4. Simplify: 2×(2x + 5) = 38
5. Expand: 4x + 10 = 38
6. Solve the equation: 4x = 28 → x = 7
7. So the width is 7 cm and the length is 7+5=12 cm
8. Area calculation: Area = length × width = 12 × 7 = 84 square centimeters
verify:
Circumference = 2×(12 + 7) = 2×19 = 38 cm, which meets the requirements of the question
Area = 84 cm2
Answer: The area of this rectangle is 84 square centimeters
The thought chain method has developed several important variants: Zero-shot CoT Kojima et al., 2022 [3] stimulates reasoning through simple trigger phrases; Self-consistent CoT Wang et al., 2022 [4] uses multi-path reasoning and majority voting to improve reliability; Automatic CoT Zhang et al., 2022 [5] can automatically generate high-quality examples. Interested students can read more.
Tree of Thoughts (ToT)
Figure: Tree of Thoughts framework (Source: Yao et al. 2023 [6] )
The thinking tree framework expands CoT into a tree structure. By constructing the thinking process into a tree structure , multiple thinking branches are generated at each decision point , combined with search algorithms to explore the solution space , and using a self-evaluation mechanism to select the optimal path to solve complex problems that require exploration or strategic foresight.
ToT is particularly suitable for complex tasks that require exploring multiple solutions , such as strategic games (chess, 24 points, etc.) and scenarios that require forward thinking. It explores the solution space by maintaining multiple parallel reasoning paths, supporting backtracking and forward planning , and combining search algorithms (such as BFS, DFS, Beam Search). ToT's self-evaluation mechanism enables it to perform well in complex decision-making and planning problems. However, ToT has high computational cost and implementation complexity , and requires an effective evaluation mechanism to guide the search process. In some cases, it may fall into a local optimal solution and fail to find the global optimal solution.
Algorithm flow:
1. Thinking: Generate multiple possible thoughts at each node 2. Evaluation: Evaluate the value of each thought 3. Search: Choose the most promising path to continue exploring 4. Iteration: Repeat the above process until the problem is solved
ReAct Prompting (Reasoning + Action)
Figure: ReAct's "think-act-observe" iterative process
ReAct (Reasoning+Acting) combines reasoning trajectories and actual actions. By alternating reasoning (Reasoning) and action (Acting) , it uses external tools to obtain real-time information , adjusts the reasoning path based on the observation results , and forms a "thinking-action-observation" closed loop. It allows the model to interact with external tools and the environment to obtain information and form a closed-loop decision-making system.
ReAct Prompting is particularly suitable for question-answering systems and multi-step decision-making that require external knowledge . By alternating reasoning and action, it significantly reduces factual illusions and supports the decomposition of complex tasks . It is mainly used in four scenarios: information retrieval and verification (such as querying real-time data, verifying facts), complex problem solving (such as mathematical calculations, programming debugging), dynamic decision making (such as investment decisions, travel planning) and interactive task processing (such as intelligent customer service, data collection). Although ReAct is powerful and flexible, it is also highly dependent on the quality of external tools , and in some cases the sequence of actions may become lengthy and inefficient.
Example:
Task: Find the best laptop for business people in 2025 and explain why.
Think about it: You need to find a laptop that is suitable for business people. You should consider performance, portability, battery life and business functions.
Action: Search [2025 Business Laptop Rankings]
Observation: The search results show that popular business notebooks include ThinkPad X1, MacBook Pro, Dell XPS and HP Elite series.
Think about it: You need to understand the specific parameters and business features of these computers.
Action: Search [ThinkPad X1 vs MacBook Pro business features comparison]
Observation: ThinkPad offers more business security features and interfaces, MacBook has better performance but fewer interfaces, Dell balances performance and portability, and HP offers comprehensive enterprise management solutions.
Thinking: Based on the information, recommendations can be given.
Answer: I recommend the ThinkPad X1 as the best business notebook for its excellent security features (fingerprint recognition + facial recognition), rich interfaces suitable for business scenarios, military-grade durability, and enterprise-level management features. If you are more concerned about performance, you can consider the MacBook Pro; if your budget is limited, the Dell XPS is also a good choice.
Tool integration and application scenarios: ReAct can integrate a variety of external tools to enhance its capabilities, including search engines to obtain real-time information, calculators to process mathematical operations, professional knowledge base query systems, various API services, and code execution environments. These tools enable ReAct to handle a wide range of tasks from daily information queries to professional field issues, and are particularly suitable for scenarios that require the latest information or professional knowledge, such as travel planning, technical support, medical consultation, and financial analysis.
Reflexion
Figure: The three-stage cycle of the Reflexion framework (based on Shinn et al. 2023 [7] )
The Reflexion framework uses a three-stage cycle: action, evaluation, and reflection to strengthen the model through verbal feedback. It provides verbal feedback rather than numerical rewards , remembers past mistakes and forms improvement strategies , cultivates self-criticism and metacognitive abilities , enables the model to learn from mistakes, and realizes a closed-loop system of self-improvement.
System components : The Reflexion framework consists of three core components: Actors are responsible for executing tasks, Evaluators judge the quality of results, and Reflectors analyze the causes of failure and propose improvement strategies. The three work together to form a self-improvement closed loop.
Scenarios and limitations: Reflexion is particularly suitable for iterative tasks that require learning from errors , such as debugging and optimizing programming problems. It includes three roles: actor, evaluator, and self-reflection, forming a complete "action-evaluation-reflection" cycle , which can learn from trial and error and continuously improve. Reflexion provides detailed language feedback rather than simple rewards, and maintains reflection memory, which enables it to perform well in long-term learning and self-improvement scenarios. However, Reflexion requires a high-quality evaluation mechanism , may fall into local optimal solutions, and the reflection process itself may introduce new errors. In addition, its computational and storage overhead is large , and it has high requirements on system resources.
Example:
Task: Write a function to calculate the Fibonacci sequence
Attempt 1:
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
Evaluation: The function is correct but inefficient, with a time complexity of O(2^n)
Reflection: My implementation uses a recursive approach, which is inefficient for large numbers. I should use dynamic programming or an iterative approach to optimize performance.
Attempt 2:
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
fib = [0, 1]
for i in range(2, n+1):
fib.append(fib[i-1] + fib[i-2])
return fib[n]
Evaluation: Correct and efficient, time complexity is O(n)
Graph Prompting
Figure: Example of Graph Prompting framework (Source: Liu et al. 2023 [8] )
Graph Prompting structures prompts into a directed graph, organizing prompts into a graph structure of nodes and edges , where each node represents a specific subtask or reasoning step , and the edges represent the dependencies and information flow between tasks . It also supports conditional branches and loop structures , allowing the model to reason and make decisions along a predefined path, thereby achieving more complex task process control.
Scenarios and limitations: Graph Prompting is particularly suitable for complex tasks with clear processes and dependencies , such as multi-step planning, conditional decision-making, and recursive problem solving. It effectively reduces complexity and improves controllability by decomposing large tasks into interconnected subtasks, and supports nonlinear reasoning paths and conditional execution, making it perform well when dealing with tasks that require clear process control. Graph Prompting also supports modular design for easy reuse and maintenance. However, designing an effective graph structure requires expertise , has high implementation complexity, and may cause errors to accumulate during execution. In addition, large graph structures may exceed the context window limit and require special processing mechanisms.
Example:
Implementation: Graph Prompting can be implemented in a variety of ways: static graphs predefine the complete task flow; dynamic graphs adjust the structure in real time based on intermediate results; nested graphs allow nodes to contain subgraphs; and it can also be combined with other prompting technologies (such as CoT, ReAct) to form a hybrid method to adapt to tasks of different complexity.
Summary and Best Practices
Prompt engineering is a rapidly developing discipline, and different prompting techniques are suitable for different scenarios. Choosing an appropriate prompting technique should take into account task complexity, external knowledge requirements, interpretability requirements, and available computing resources. For simple tasks, Zero-Shot is the first choice; complex reasoning problems are suitable for using CoT or ToT; ReAct performs well when external knowledge is required; Reflexion should be considered for long-term learning scenarios; and Graph Prompting is suitable for structured process tasks. These techniques can be used in combination to cope with more complex scenarios, such as ReAct+Reflexion for interactive tasks of continuous learning, and Few-Shot+CoT to improve the effectiveness of examples for complex tasks. As model capabilities improve, it is recommended to continue to pay attention to the latest research progress in prompt engineering and build a prompt library that suits you through practice.