Updated on 2025-11-19 GMT+08:00

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting enhances the LLM's performance for complex reasoning tasks, such as mathematical or logical reasoning. By offering examples or requesting the LLM to provide intermediate reasoning steps, you can steer the model to produce more accurate results.

  1. Single-shot/Multi-shot CoT

    When crafting prompts, incorporating examples enables the LLM to learn prior to responding to queries. When using this approach, remember to guide the LLM not to replicate the provided examples, but instead encourage it to generate unique and diverse content. Alternatively, you can instruct the LLM to adopt the style and generation method of the given examples, without copying their exact content.

    Example 1: Provide examples for the model to learn the problem-solving logic.

    Before the optimization:There are 18 bicycles and tricycles in the parking lot, with a total of 48 wheels. How many bicycles and tricycles are there?Model answer:There are 9 bicycles and 9 tricycles in the parking lot.
    After the optimization:<Start>Question: There are bicycles (2 wheels each) and tricycles (3 wheels each) in the parking lot. Together, there are 7 vehicles and a total of 19 wheels. How many bicycles and tricycles are there?Procedure: Let's solve this using a simple system of equations. Assume that there are x bicycles and y tricycles. We are given two pieces of information: the total number of bicycles and tricycles is 7, and the total number of wheels is 19. We can set up the following two equations: 1. x + y = 7; 2. 2 * x + 3 * y = 19. The equation 2 * x + 3 * (7 - x) = 19 can be solved, and x = 5 and y = 2 can be obtained. The final answer is: There are 2 bicycles and 5 tricycles in the parking lot.<End>Refer to the preceding example to answer the question: There are 18 bicycles and tricycles in the parking lot, with a total of 48 wheels. How many bicycles and tricycles are there?Model answer:The answer can be obtained by solving equations. Assume that there are x bicycles and y tricycles. According to the question, the total number of bicycles and tricycles is 18, and the total number of wheels is 48. Therefore, we can set up the following two equations:1. x + y = 18; 2. 2x + 3y = 48.We first solve one equation to get the value of x, and then use this value to solve the other equation to get the value of y.Step 1: Solve the first equation for x: x + y = 18; y = 18 - x.Step 2: Substitute into the second equation: 2x + 3y = 48; 2x + 3(18 - x) = 48; 2x + 54 - 3x = 48; x = 6.Step 3: Plug x = 6 back into the second equation: 2 * 6 + 3y = 48; 12 + 3y = 48; 3y = 36; y = 12.Therefore, there are 6 bicycles and 12 tricycles in the parking lot.

    Example 2: Provide examples and ask the model to create new content in a similar style.

    Zero shot:Please write five e-commerce copy examples, each around 20 words. Use vivid and engaging language.Product: Sealed storage box; Selling points: Airtight design locks in freshness and keeps items protected; clever storage compartments maximize space and organization; enjoy instant discount when you place your order.Model answer:1. "Unlock an orderly life—one airtight box at a time!"2. "No more lost items—keep everything safe and secure!"3. "Super-sealed freshness meets smart storage power!"4. "Tidy, protected, and stress-free—order your storage hero today!"5. "Get your order in for instant discounts and special surprises!"
    Multiple shots:High-quality e-commerce copy examples:1. Stock up and store with style—adding warmth and comfort to your everyday life!2. One box, countless memories—keep what matters close.3. Let us help you organize your life, the smarter way.4. Decluttering is a never-ending journey—but we make it easier.5. Store all your favorites, little surprises, and treasured items in one place.6. Experience the simple joy of sharing life's beautiful moments.7. As the saying goes, "All things come in threes." Store everything neatly in one go.8. If you can't decide to let go—store it with peace of mind.9. Unlock more possibilities for your life, your way.Learn the style of the preceding examples and write five more e-commerce copy examples, each around 20 words. Use vivid and engaging language.Product: Sealed storage box; Selling points: Airtight design locks in freshness and keeps items protected; clever storage compartments maximize space and organization; enjoy instant discount when you place your order.Model answer:1. Freeze time, embrace order—life sparkles when every moment finds its place.2. Tuck your favorite memories and surprises into our life-sized treasure box.3. Life's hidden beauty is calling—capture it all in one organized collection.4. Your story, neatly arranged—our storage box is more than just a container.5. Tame chaos with smart storage—elevate your space, simplify your life.
  2. Zero shot

    When dealing with zero-shot tasks, particularly those involving complex reasoning or mathematical problems, you can guide the LLM to think step-by-step. This can be achieved by adding phrases like "Work through the problem step by step" or "Let's think step by step" to the original prompt. When receiving such instructions, the LLM breaks a reasoning task down into manageable steps. This not only simplifies the process but enhances the explainability of the model's output. This approach gives the LLM more time to reason its responses. The inclusion of its "thinking" time, represented by the consumption of more computing resources, results in better model reasoning and better outcomes.

  3. Self-consistency

    This approach allows an LLM to sample a diverse set of reasoning paths generated from the same prompt and then select the most consistent answers.

    Example: Ask the question multiple times and select the answer with the highest probability.

    Question: There are 17 heads and 42 legs in a cage with chickens and rabbits. How many chickens and rabbits are there?Model answer 1: {Omitted analysis process} There are 15 chickens and 2 rabbits.Model answer 2: {Omitted analysis process} There are 8 chickens and 9 rabbits.Model answer 3: {Omitted analysis process} There are 13 chickens and 4 rabbits.Model answer 4: {Omitted analysis process} There are 7 chickens and 10 rabbits.Model answer 5: {Omitted analysis process} There are 13 chickens and 4 rabbits.Model answer 6: {Omitted analysis process} There are 13 chickens and 4 rabbits.Model answer 7: {Omitted analysis process} There are 8 chickens and 9 rabbits.Model answer 8: {Omitted analysis process} There are 13 chickens and 4 rabbits.Model answer 9: {Omitted analysis process} There are 7 chickens and 10 rabbits.Model answer 10: {Omitted analysis process} There are 13 chickens and 4 rabbits.