Loading...

Loading...

Reasoning Prompting Techniques
Loading like and share buttons...
#prompting#llm#ai#softwaredevelopment

Reasoning Prompting Techniques

Tomer Raitz
Tomer Raitz
Jan 22β€’5 min read

Last time we talked about Basic Prompting Techniques which focused on simple input-output. Now, let’s explore Reasoning Prompting Techniques.

1. Chain-of-Thought (CoT)

This is the foundational technique to activate reasoning in an LLM. It forces a linear thought process, thinking down one path and taking it as the "true" flow.

When to use it:

  • Math & Logic: Solving word problems or arithmetic where the answer depends on the previous calculation.
  • Simple Debugging: Tracing a variable through a short function.
  • Sequential Tasks: "First do X, then do Y."

Example to Zero-Shot CoT:

🐍Python
1
2
Prompt: Explain what this code does. 
Let's think step by step. (Note: That magic phrase "Let's think step by step" is what triggers the reasoning chain!)

Example to Few-Shot CoT:

🐍Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
System: You are a precise log analysis engine.

User:
I need you to extract the 'ErrorID' and 'UserID' from these log lines.

--- EXAMPLE 1 (Shot 1) ---
Input: "2024-01-22 [CRITICAL] Connection refused for session 55921 (user: admin_01) - Retry count 3"

Thinking:
1. Scan for the error level. It is [CRITICAL], but I need the ErrorID.
2. The message says "Connection refused". There is no explicit numeric Error code here.
3. Look for the UserID. I see "user: admin_01".
4. Conclusion: UserID is "admin_01", ErrorID is "null" (not found).

Output: {"ErrorID": null, "UserID": "admin_01"}
...

2. Tree of Thoughts (ToT)

This is a more advanced reasoning technique. Here, the LLM explores more than one path. It creates several "branches" of thought, evaluates them, and then selects the most promising one to continue.

When to use it:

  • Creative Writing: Generating plot points where you want to explore different narrative twists before committing.
  • Strategic Planning: Business strategies where you need to forecast different outcomes for different decisions.
  • Complex Coding: exploring different algorithms to solve a problem before implementing the most efficient one.

Example:

🐍Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
prompt:

Role: You are an expert problem solver using the Tree of Thoughts method.

Task: [Insert your complex problem here]

Process:

Brainstorming (Branches): Generate 3 distinct, mutually exclusive solutions or approaches 
(Option A, B, C). Do not evaluate them yet.

Evaluation: Critically analyze the pros, cons, and risks of each option. 
Assign a probability of success (0-100%) to each.

Selection & Expansion: Pick the two most promising options. 
...

3. Graph of Thoughts (GoT)

This is the most advanced and complex reasoning technique. It treats thoughts as a network (graph), allowing the model to compare and combine different nodes at every step.

When to use it:

  • Sorting & Aggregation: "Take these 5 conflicting news reports and synthesize the absolute truth."
  • Complex Document Summarization: Summarizing different sections of a book and then combining those summaries into a master abstract.
  • Recursive Optimization: Refining a piece of code by looping it through a review process until it meets specific criteria.

Example:

🐍Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
prompt:

Task: [Write the task, e.g., "Optimize this Python function for speed and readability"]

Execution Strategy: Graph of Thoughts

Step 1: Expansion (Generate Nodes) Generate 3 distinct,
 independent approaches to solving this problem. Do not critique them yet. 
 Label them Node A, Node B, and Node C.

Step 2: Transformation (Refine Nodes) For each Node (A, B, C), 
identify one flaw and improve it. Output the improved versions as A2, B2, C2.

Step 3: Aggregation (The Merge) This is the key GoT step. 
Compare A2, B2, and C2. identifying the strongest elements of each. 
...

3. Self-Consistency

This technique prioritizes reliability. The LLM generates a Chain-of-Thought multiple times and "votes" on the most frequent answer. It is essentially a "majority rules" filter for hallucinations.

<img src="https://pccqnuqlacsnvstprfsu.supabase.co/storage/v1/object/public/blog-content/inline/e1c1ff2d-96dd-447a-90ac-da98e8ad64fc/2f5efa9a-7557-4115-8012-61443d952126.jpg" alt="Image" width="619" height="338"">

When to use it:

  • Math & Arithmetic: Ensuring calculations are correct (e.g., $24 \times 12$).
  • Fact Verification: Checking if a specific date or name is consistent.
  • Logic Puzzles: Tasks with one definitive "Right" answer. (Note: Do not use this for creative tasks, as you cannot "vote" on the best poem).

Comments

0 comments

Enter your comment. Maximum 2000 characters.

No comments yet. Be the first to share your thoughts!
Vibki logo wave icon
Vibki Surfing Bot
Vibki

Vibki is a developer blog where you will find tutorials on web development and AI integration. Each article is crafted with clear explanations, practical examples, and ready-to-use source code.

Talk to me
Copy email
LinkedIn
GitHub
Dev.to