General Prompting / Zero-Shot
This is the most basic form of prompting where you provide the LLM with a task description or question without giving it any specific examples of the desired output. The model relies solely on its pre-training to understand and execute the task.
Imagine giving someone a box of assorted LEGOs and saying "Build a car." You don't show them a picture of a car or any example steps; you rely on their general knowledge of what a car is and how LEGOs work.
Prompt:
Classify movie reviews as POSITIVE, NEUTRAL or NEGATIVE.
Review: "Her" is a disturbing study revealing the direction humanity is headed if AI is allowed to keep evolving, unchecked. I wish there were more movies like this masterpiece.
Sentiment:
Output: POSITIVE
One-Shot & Few-Shot Prompting
Instead of just describing the task, you provide the LLM with one (one-shot) or multiple (few-shot) examples of the task being performed correctly. These examples help the model understand the desired output format, style, or pattern. Generally, 3-5 examples are a good starting point for few-shot. Providing examples is considered a highly effective best practice.
One-Shot: You show someone one picture of a specific LEGO car and say, "Build something like this."
Few-Shot: You show someone pictures of 3-5 different LEGO cars (a sedan, a truck, a sports car) and say, "Build another car following these kinds of designs."
Example :
Prompt:
Parse a customer's pizza order into valid JSON:
I want a small pizza with cheese, tomato sauce, and pepperoni.
JSON Response:
{
"size": "small",
"type": "normal",
"ingredients": [["cheese", "tomato sauce", "peperoni"]]
}
Can I get a large pizza with tomato sauce, basil and mozzarella
JSON Response:
{
"size": "large",
"type": "normal",
"ingredients": [["tomato sauce", "bazel", "mozzarella"]]
}
Now, I would like a large pizza, with the first half cheese and mozzarella. And the other tomato sauce, ham and pineapple.
JSON Response:
Output:
{
"size": "large",
"type": "half-half",
"ingredients": [["cheese", "mozzarella"], ["tomato sauce", "ham", "pineapple"]]
}
System Prompting
This technique involves setting the overall context, purpose, or rules for the LLM's behavior before the main prompt or conversation starts. It defines the 'big picture' or provides specific instructions on how the output should be formatted or constrained. It can also be used to enforce safety or toxicity guidelines.
Before handing over the LEGOs, you give instructions like: "You are a master LEGO architect. Build vehicles only, use only red and blue bricks, and make sure every vehicle has wheels."
Prompt:
Classify movie reviews as positive, neutral or negative. Only return the label in uppercase.
Review: "Her" is a disturbing study revealing the direction humanity is headed if AI is allowed to keep evolving, unchecked. It's so disturbing I couldn't watch it.
Sentiment:
Output: NEGATIVE
Role Prompting
You assign a specific persona, character, or identity for the LLM to adopt. This helps tailor the model's tone, style, knowledge, and behavior to be consistent with the assigned role.
You tell the person building with LEGOs: "You are a pirate building a treasure chest" or "You are an astronaut building a spaceship." Their creations and the way they talk about them will reflect that role.
Prompt:
I want you to act as a travel guide. I will write to you about my location and you will suggest 3 places to visit near me. In some cases, I will also give you the type of places I will visit. My suggestion: "I am in Amsterdam and I want to visit only museums."
Travel Suggestions:
Output:
1. Rijksmuseum: World-renowned museum, known for Dutch masterpieces like Rembrandt’s “The Night Watch.” ...
2. Van Gogh Museum: Immerse yourself in the captivating works of Vincent van Gogh. ...
3. Stedelijk Museum Amsterdam: Discover modern and contemporary art...
Contextual Prompting
Providing specific background information, details, or context relevant to the current task or conversation. This helps the model understand nuances and tailor the response more accurately to the immediate situation.
While someone is building a LEGO house, you give them extra context: "Remember, this house is for a family with two dogs, so it needs a backyard and a doghouse."
Prompt:
Context: You are writing for a blog about retro 80's arcade video games. Suggest 3 topics to write an article about with a few lines of description of what this article should contain.
Output:
1. The Evolution of Arcade Cabinet Design:
This article would explore the evolution of arcade cabinet designs...
2. Blast From The Past: Iconic Arcade Games of The 80’s:
- This article would feature a glimpse into the history, impact, and legacy...
3. The Rise and Retro Revival of Pixel Art:
- This article would delve into the evolution of pixel art
Step-Back Prompting
Instead of tackling a specific question directly, you first ask the LLM a more general, high-level question or ask it to derive principles related to the specific task. The answer to this general question is then fed back into the prompt for the original, specific task, helping the model activate relevant knowledge and reasoning pathways.
Instead of asking "Build this specific LEGO spaceship model X," you first ask, "What are the key principles of building sturdy and cool-looking LEGO spaceships?" Then, using those principles, you ask, "Now, build spaceship model X using those principles."
Step 1 (Step Back): Ask "Based on popular first-person shooter action games, what are 5 fictional key settings that contribute to a challenging and engaging level storyline...?" -> Get settings like "Abandoned Military Base", "Cyberpunk City", "Underwater Research Facility", etc..
Step 2 (Original Task with Context): "Context: [List of settings from Step 1]. Take one of the themes and write a one paragraph storyline for a new level of a first-person shooter video game..." -> Get a storyline based on one of those themes, like the Underwater Facility.
Chain of Thought (CoT)
Encouraging the LLM to generate intermediate reasoning steps before giving the final answer, mimicking a step-by-step thinking process. This is particularly useful for tasks requiring logic, arithmetic, or complex reasoning. Adding phrases like "Let's think step-by-step" triggers this. It improves accuracy and interpretability, as you can see the model's reasoning. It works best when combined with few-shot examples showing the reasoning steps.
Instead of just showing the finished LEGO castle, you ask the builder to narrate their process: "First, I'll build the base. Then, I'll add the corner towers. Next, I'll connect them with walls..." This helps ensure they don't miss a step and you can see how they arrived at the final castle.
Prompt:
When I was 3 years old, my partner was 3 times my age. Now, I am 20 years old. How old is my partner? Let's think step by step.
Output:
1. Let’s assume my current age is “x” years.
2. When I was 3 years old, my age was 3 years.
3. My partner’s age at that time was 3 times my age, which means my partner’s age was 3 3 = 9 years.
4. Now, I am 20 years old, which means my age has increased by 20 - 3 = 17 years since I was 3 years old.
5. Since my partner’s age was 9 years when I was 3 years old, and my age has increased by 17 years, my partner’s age must have also increased by 17 years.
6. Therefore, my partner’s current age is 9 + 17 = 26 years.
So, my partner is 26 years old.
Self-Consistency
An enhancement over basic CoT. Instead of generating just one chain of thought, you prompt the LLM multiple times (using higher temperature settings for variability) to generate several different reasoning paths for the same problem. You then extract the final answer from each path and choose the most frequent (most consistent) answer as the final result. This improves accuracy, especially on complex reasoning tasks.
You ask 5 different LEGO builders to build a bridge following the same vague instructions ("Build a strong bridge"). They might use slightly different techniques (reasoning paths). You look at all 5 finished bridges and see which design approach was used most often, assuming that the most common approach is likely the most reliable.
Imagine classifying the "Harry the Hacker" email.
Attempt 1: CoT reasoning leads to "IMPORTANT".
Attempt 2: Different CoT reasoning leads to "NOT IMPORTANT".
Attempt 3: Yet another CoT path leads to "IMPORTANT".
Conclusion: Since "IMPORTANT" appeared 2 out of 3 times, self-consistency selects "IMPORTANT" as the final answer.
Tree of Thoughts (ToT)
Generalizes CoT by allowing the LLM to explore multiple reasoning paths simultaneously. Instead of a single chain, it maintains a tree structure where each node is a thought (an intermediate step), and the model can branch out, explore different reasoning directions, evaluate them, and backtrack if necessary. It's better suited for complex problems requiring exploration.
Building a complex LEGO Technic model. At step 5, there are three possible ways (branches) to attach a specific gear assembly. The builder tries way A, sees it won't work later. Backtracks. Tries way B, it looks promising. Also explores way C briefly. Decides way B is the best path forward and continues building from there.
Example: While the provided document mentions ToT and links to a notebook, it doesn't give a simple text example. Conceptually, for a complex logic puzzle, ToT might generate:
Thought 1: Initial state.
Branch A -> Thought 2A -> Thought 3A (Leads to contradiction, backtrack)
Branch B -> Thought 2B -> Thought 3B -> Branch B1 -> Thought 4B1 (Looks promising)
Branch B -> Thought 2B -> Thought 3B -> Branch B2 -> Thought 4B2 (Possible, but less likely than B1)
Proceed down path B1.
ReAct (Reason & Act)
Combines reasoning (like CoT) with the ability to take actions using external tools (like performing a web search, running code, or querying an API). The LLM generates a thought about what it needs to do, decides on an action (e.g., search the web), performs the action, observes the result (e.g., search results), and then uses that observation to generate the next thought and action, iterating until the task is solved. This allows LLMs to interact with the world and retrieve up-to-date information.
Building a LEGO model from instructions you don't have.
Thought: "I need to know how the wing attaches."
Action: Look up the instructions online (using a tool).
Observation: See the diagram showing the wing attachment.
Thought: "Okay, now I know how to attach the wing. Next, I need the roof piece."
Action: Search the LEGO box (physical action/tool).
Observation: Find the roof piece.
Prompt: How many kids do the band members of Metallica have?
Output:
Thought: I need to find the members of Metallica and how many kids each has. Metallica has 4 members.
Action: Search [How many kids does James Hetfield have?]
Observation: three children
Thought: James has 3. Need Lars.
Action: Search [How many kids does Lars Ulrich have?]
Observation: 3
Thought: Lars has 3. James(3)+Lars(3)=6. Need Kirk.
Action: Search [How many kids does Kirk Hammett have?]
Observation: They have two sons...
Thought: Kirk has 2. James(3)+Lars(3)+Kirk(2)=8. Need Robert.
Action: Search [How many kids does Robert Trujillo have?]
Observation: 2
Thought: Robert has 2. James(3)+Lars(3)+Kirk(2)+Robert(2)=10. I have all members.
Final Answer: 10
Chain of Draft (CoD) - BONUS
Inspired by how humans jot down concise notes, CoD aims to be more efficient than CoT by generating minimalistic intermediate reasoning steps. Instead of verbose explanations, each step contains only the essential information (e.g., just the calculation or key term), often limited to a very small number of words. This significantly reduces the number of tokens used, lowering latency and cost while maintaining comparable accuracy, especially in few-shot scenarios.
Instead of writing full sentences for instructions like "Take the long blue 2x8 brick and attach it to the gray baseplate," the instructions are just shorthand notes: "Blue 2x8 -> Gray base." It conveys the core step much more efficiently.
Example: CoT Style: "Initially, Jason had 20 lollipops. After giving some away, he has 12. To find the difference, subtract 12 from 20. 20 - 12 = 8. So he gave away 8."
CoD Style: 20 - x = 12; x = 20 - 12 = 8. (Captures the essential math with minimal words).
Automatic Prompt Engineering (APE)
Using an LLM to help generate or refine prompts for another task. You essentially prompt one LLM to create multiple candidate prompts for a specific goal. These generated prompts are then evaluated (either by another LLM or using metrics like ROUGE/BLEU), and the best-performing one is selected or further refined.
You want the best instructions for building a LEGO tower. You ask five different experienced LEGO builders (LLMs) to write down their best instructions (prompts). You then compare their instructions (evaluate prompts) and pick the clearest and most effective set.
Prompt:
We have a band merchandise t-shirt webshop, and to train a chatbot we need various ways to order: "One Metallica t-shirt size S". Generate 10 variants, with the same semantics but keep the same meaning.
Output:
1. I’d like to purchase a Metallica t-shirt in size small.
2. Can I order a small-sized Metallica t-shirt?
3. I’d like to buy one Metallica t-shirt in small.
(These outputs are then evaluated to find the best prompt variation for the chatbot)
Code Prompting
This is a broad category focused on using LLMs for code-related tasks, including generating new code from descriptions, explaining existing code, translating code between languages, and debugging or reviewing code.
Thinking of code as LEGO structures:
Writing: "Build me a LEGO bridge that can span 12 inches." (Describing what code should do).
Explaining: "Tell me how this pre-built LEGO car's steering mechanism works." (Understanding existing code).
Translating: "Rebuild this LEGO house using only Technic bricks instead of standard bricks”
Debugging: "This LEGO crane keeps collapsing, tell me why and how to fix it."
Example:
Writing Code: "Write a code snippet in Bash, which asks for a folder name... renames all the files inside by prepending the name draft..." -> Generates Bash script.
Explaining Code: "Explain to me the below Bash code: [code snippet]" -> Generates a step-by-step explanation of the script.
Translating Code: "Translate the below Bash code to a Python snippet. [Bash code snippet]" -> Generates equivalent Python code.
Debugging Code: "The below Python code gives an error: [Traceback and code snippet] Debug what's wrong and explain how I can improve the code." -> Identifies the error (e.g., undefined function) and suggests fixes/improvements
Multimodal Prompting
Using multiple types of input formats (not just text) to guide an LLM, such as combinations of text, images, audio, or code, depending on the model's capabilities. The PDF focuses on text, noting multimodal is a separate concern.
Giving instructions that include a picture of the final LEGO model and written steps, or perhaps even a
video showing a tricky part being assembled.
Example: Showing an image of a specific LEGO piece and asking via text, "What is the part number for this LEGO brick?”
Mindmap of the Podlog:
Citation : https://www.kaggle.com/whitepaper-prompt-engineering