Prompt engineering is the practice of designing, refining, and optimizing inputs (prompts) for large language models (LLMs) to get a desired output.
It’s essentially the art and science of communicating effectively with an AI model. By crafting precise and well-structured prompts, you can guide the model to perform a wide range of tasks more accurately, creatively, and consistently.
Prompt Engineering is about
- going beyond questions
- providing the model with a detailed set of instructions, context, examples, and constraints
- giving a comprehensive brief rather than just a one-line request
- giving inputs on your intent, tone, and the specific information it should focus on
Key Parameters to consider while prompting
🔵 Temperature
Temperature controls creativity vs predictability in text generation.
0.0
- Fully deterministic
- The model gives the same answer every time
- Safe, factual, stable
- Best for coding, math, summaries, instructions
0.1 – 0.3 (Low)
- Slight variation
- Very reliable
- Good for professional/business writing
0.4 – 0.7 (Medium / Balanced)
- Mix of creativity + accuracy
- Good for marketing, consulting, product ideas
- Often the best default range
0.8 – 1.2 (High)
- Creative, expressive, more surprising
- Good for brainstorming, storytelling
- Risk of drifting off-topic increases
1.3 – 2.0 (Very High)
- Wild, experimental, unpredictable
- Not suitable for factual or business tasks
- Useful for art, poem generation, game ideas
Typically, you cannot set temperature numerically in the chat interface, but you can request the style:
- “Use low temperature—be precise and factual.”
- “Use high temperature—give very creative, unconventional ideas.”
🟡 Top-k
Top-k controls how many of the highest-probability words the model considers when generating each token.
- Low top-k (e.g., 10):
Only picks from the top 10 likely tokens → very focused and safe. - High top-k (e.g., 100+):
Picks from a large pool → more variety, more surprise.
Typically, you can’t input k directly, but you can tell ChatGPT:
- “Use a low top-k style—give the safest, most probable wording.”
- “Use a high top-k style—allow more possibilities and variety.”
🔴 Top-p (Nucleus Sampling)
Top-p chooses from all tokens whose probabilities add up to p.
- Low top-p (0.3–0.5):
Only the most probable phrases → steady, predictable. - High top-p (0.9–1.0):
Allows more “tail” probabilities → more diversity and creativity.
Difference from Top-k
- Top-k restricts by count (top 50 words).
- Top-p restricts by cumulative probability (top 90% probability).
Typically it is not possible to set directly in the chat interface. Hence, you can control it as below:
- “Use a low top-p style—keep responses tightly focused.”
- “Use a high top-p style—be more exploratory and creative.”
Summary
| Setting | Output Style | Good For |
|---|---|---|
| Low Temperature / Low k / Low p | Predictable, concise, factual | Summaries, analysis, policy, deterministic answers |
| Medium Settings | Balanced, practical | Business strategy, recommendations |
| High Temperature / High k / High p | Creative, surprising | Innovation, marketing ideas, brainstorming |
Prompting Techniques
Zero-Shot Prompting
This is your starting point for most tasks. You use it when you expect the model to have sufficient knowledge to complete a task without any examples.
- Use when: The task is straightforward and the model’s pre-trained knowledge should be enough. This includes simple questions, basic text generation, or common classification tasks.
- Example: “Write a short summary of the causes of the French Revolution.”
Few-Shot Prompting
You use this when the model needs to understand a specific format, style, or a new pattern that wasn’t in its training data. By providing a few examples, you teach the model the desired behavior.
- Use when: You need the model to follow a custom pattern, such as generating text in a specific format or style, or for a classification task with unique categories.
- Example: “Translate the following sentences from English to a pirate-like tone.
- I am hungry. -> I be famished.
- Where is the treasure? -> Where be the booty?
- Now, translate: ‘The ship is sinking’.”
Chain-of-Thought (CoT) Prompting
This technique is best for complex, multi-step problems that require logical reasoning or calculation. It’s especially useful for tasks where a simple, one-shot answer might be wrong.
- Use when: The problem involves multiple steps, complex math, or logical deduction. By asking the model to show its work, you improve the accuracy of the final answer and can trace its reasoning.
- Example: “The average score of 5 students in a test is 85. If a new student joins and the new average is 88, what was the new student’s score? Show your steps.”
A powerful variation is Zero-Shot CoT, where you simply append the phrase “Let’s think step by step” to a complex prompt, and the model often generates a chain of reasoning on its own.
Self-Consistency
This technique builds on Chain-of-Thought by asking the model to generate multiple, diverse reasoning paths for the same problem. The final answer is then chosen by selecting the most common or consistent answer among all the generated paths.
- When to use: For critical tasks where accuracy is paramount, especially for complex reasoning problems where the model might make a mistake in a single chain of thought.
- Example: “Solve the following problem. Generate three different chains of thought to arrive at an answer, and then state the final answer that is most consistent across the three chains.”
Tree-of-Thoughts (ToT)
This is an even more advanced technique that extends Chain-of-Thought. Instead of following a single path of reasoning, ToT encourages the model to explore multiple “thoughts” or reasoning steps simultaneously, much like exploring a tree of possibilities. It can then self-evaluate each path and prune away less promising ones.
- When to use: For tasks that require strategic planning, exploration, or where a single linear path might not be sufficient, such as complex planning, creative writing, or solving multi-agent problems.
- Example: “Plan a three-day travel itinerary for Paris. Generate three possible options with different focuses (e.g., historical, artistic, culinary). For each day, propose two different activities. Finally, choose the best overall itinerary and explain why.”
Self-Refinement / Self-Correction
This is a two-step process that mimics a human’s self-editing process. The model first generates an initial response and is then prompted to critically evaluate its own work and make corrections.
Example: “Task: Write a summary of the provided text. After writing the summary, review it for factual accuracy and conciseness. Revise the summary based on your review and provide the final version.”
Role-Playing
When to use: For tasks that require a high degree of quality, accuracy, or a polished final output, such as writing a report or debugging a piece of code. It’s especially useful for reducing “hallucinations” (plausible but incorrect information).
This technique is used to set the tone and perspective of the model’s response. It’s effective for getting answers in a specific style or from a particular point of view.
- Use when: You need the model to adopt a persona to provide a specific kind of output, such as a creative writer, a data scientist, or a customer support agent.
- Example: “You are a senior technical writer. Explain the Transformer architecture in a clear and concise manner for an audience of university students.”
One-Shot Prompting
What it is: Providing one example to guide the model’s behavior.
When to use: When you want to give a pattern but don’t need multiple examples.
Example: Prompt:
Example: “Book” → “Livre”
Now translate: “Chair” →
Output: “Chaise”
Instruction + Context Prompting
What it is: Giving both a clear instruction and relevant background information.
When to use: When the task depends heavily on context or prior knowledge.
Example:
Prompt: “Given this job description and CV, write a cover letter highlighting the candidate’s project management skills.”
Delimiters / Structured Prompting
What it is: Using special symbols (###, “””, etc.) to separate instructions, context, and examples.
When to use: To avoid confusion when prompts are long or contain multiple components.
Example:
Prompt:
### Instruction: Summarize the text below in 1 sentence. ### Text: The conference will bring together experts from around the world to discuss AI advancements.Output: “The conference gathers global experts to discuss AI progress.”
ReAct Prompting (Reason + Act)
What it is: Instructing the model to alternate between reasoning and taking an action (e.g., calling a tool).
When to use: For tasks where the model needs to search, query APIs, or use external data before answering.
Example:
Prompt: “Think about the answer, then use the search tool to verify before responding.”
Multimodal Prompting
What it is: Combining text with other inputs like images, audio, or tables.
When to use: When the model can process more than one modality (e.g., GPT-4 with vision).
Example:
Prompt: “Look at this image and describe the weather conditions.” (with photo attached)
Iterative Prompting
What it is: Refining prompts based on previous responses to gradually improve output.
When to use: For complex creative tasks or when early responses need improvement.
Example:
Step 1 Prompt: “Write a short story about space exploration.”
Step 2 Prompt: “Rewrite it with more focus on the astronaut’s emotions.”
Prompt Chaining
What it is: Breaking a complex task into multiple smaller prompts and chaining the outputs.
When to use: For workflows like summarization → analysis → formatting.
Example:
- Prompt: “Summarize the article.”
- Prompt: “List 3 key challenges mentioned in the summary.”
Summarizing the above discussion
- Zero-shot prompting: Asking the model to perform a task without providing any examples. This relies entirely on the model’s pre-trained knowledge.
- One-shot prompting: Providing one example to guide the model’s behavior.
- Few-shot prompting: Giving the model a few examples of the task and the desired output within the prompt itself. This teaches the model the pattern you want it to follow.
- Chain-of-Thought prompting: Instructing the model to break down a complex problem into a series of intermediate steps. This helps the model “reason” through a problem and often leads to more accurate final answers, especially for multi-step questions or calculations.
- Zero-shot CoT: Simply append the phrase “Let’s think step by step” to a complex prompt
- Self-Consistency: builds on Chain-of-Thought by asking the model to generate multiple, diverse reasoning paths for the same problem. The final answer is then chosen by selecting the most common or consistent answer among all the generated paths.
- Tree-of-Thoughts (ToT): Instead of following a single path of reasoning, ToT encourages the model to explore multiple “thoughts” or reasoning steps simultaneously, much like exploring a tree of possibilities. It can then self-evaluate each path and prune away less promising ones.
- Self-Refinement / Self-Correction: This is a two-step process that mimics a human’s self-editing process. The model first generates an initial response and is then prompted to critically evaluate its own work and make corrections.
- Role-Playing: Assigning a specific persona to the model, such as “You are a senior data analyst.” This guides the model to adopt a particular tone, style, and domain-specific knowledge
- Instruction + Context Prompting: Giving both a clear instruction and relevant background information.
Choosing the technique
Choice of the prompt engineering technique depends on the complexity of the task and the level of guidance the model needs.