Prompt engineering is **the practice of designing inputs to large language models (LLMs) that yield optimal responses.** As LLMs become integral tools across industries, the ability to craft effective prompts is increasingly vital.
Whether you're developing AI applications, creating content, coding, researching, or automating tasks, a well-engineered prompt is your gateway to unlocking the full potential of LLMs.
Effective prompt engineering is not just about asking a question. It's about speaking the model's language - **structuring context, defining roles, controlling tone, output format, and logic flow.
At the end of the document you can also find a few Prompt Engineering Guides.
## **1. Understanding LLMs and the Role of Prompts**
### **What is a Large Language Model (LLM)?**
LLMs are advanced AI systems trained on massive datasets to understand and generate human-like text. They're prediction engines: given a prompt, they predict the next most likely token (word or subword). This seemingly simple mechanic gives rise to extraordinary capabilities.
### **Why Prompt Engineering Matters?**
- Prompts shape the behavior of LLMs.
- Poor prompts lead to vague, incorrect, or verbose results.
- Structured prompts reduce hallucinations and bias.
- Custom prompts personalize and fine-tune responses without retraining the model
## **2. Key Parameters for Prompting**
To get consistent, reliable, and creative outputs, you must understand how to adjust:
- **Temperature:** Adjusts how random or deterministic the AI's responses are - lower values (e.g., 0.2) make it more focused and predictable, while higher values (e.g., 0.8) make it more diverse and creative by increasing randomness in word choice.
- **Top-k:** Restricts the model’s choices to the top k most likely next words, helping maintain control and coherence by filtering out less probable options. Think of this as narrowing the model’s choices to its _k_ favorite words. For example, if **k = 10**, the model picks the next word from only its 10 most likely options. This helps control the creativity and keeps it from going off-track.
- **Top-p (nucleus sampling):** Instead of picking a fixed number like in Top-k, Top-p looks at the top words whose combined probability adds up to a set threshold (like 90%). It’s like saying: “Only consider the most likely words until they add up to 90% confidence,” which gives the model more flexibility while still keeping things grounded.
>[!tip]
>- Top-k controls how many word options. Top-p controls how likely the chosen words are.
- **Max Tokens:** Sets a hard limit on the number of tokens (words or subwords) the model can generate in one response, which helps avoid run-on outputs or excessive length.
Example of two different parameters:
- Precision: Temp = 0.2, Top-p = 0.9, Top-k = 20
- Creativity: Temp = 0.9, Top-p = 0.95, Top-k = 40
When you're aiming for **precision**, settings like Temperature = 0.2, Top-p = 0.9, and Top-k = 20 tell the AI to be focused, consistent, and safe—ideal for tasks like writing technical instructions, summarizing factual content, or generating code. The low temperature ensures the model picks the most likely responses with minimal randomness, while the moderate Top-p and Top-k slightly open the door for nuanced phrasing without straying off-topic.
In contrast, when you want **creativity**, settings like Temperature = 0.9, Top-p = 0.95, and Top-k = 40 give the model room to experiment with more diverse, imaginative outputs. This setup encourages the AI to pull from a broader range of word choices, generating responses that are more colorful, expressive, or surprising—perfect for storytelling, ideation, or creative writing.
Here is what a setting for each parameter means:
|**Setting**|**Low**|**Mid**|**High**|**Best For**|
|---|---|---|---|---|
|**Temperature**|0.1–0.3 (very focused)|0.4–0.7 (balanced)|0.8–1.0 (imaginative)|Low: factual tasks <br>Mid: formal writing <br>High: creative writing|
|**Top-p**|0.7–0.85 (tight filter)|0.85–0.95 (moderate flexibility)|0.95–1.0 (very open-ended)|Low: technical precision <br>Mid: conversational tasks <br>High: brainstorming|
|**Top-k**|5–20 (strict word choices)|20–50 (flexible)|50–100+ (wide exploration)|Low: structured outputs <br>Mid: varied tone <br>High: diverse ideas|
And the combination of different parameters:
| **#** | **Temperature** | **Top-p** | **Top-k** | **Best For** |
| ----- | --------------- | ----------- | ---------- | ----------------------------------------------------------------------------------- |
| 1 | Low (0.2) | Low (0.8) | Low (20) | Highly structured tasks, factual Q&A, legal/compliance writing, formulaic responses |
| 2 | Mid (0.5) | Low (0.8) | Low (20) | Concise technical writing, SEO meta descriptions, knowledge recall |
| 3 | Mid (0.5) | Mid (0.9) | Low (20) | Balanced blog intros, clear summaries, academic writing |
| 4 | Mid (0.5) | Mid (0.9) | Mid (50) | General-purpose tasks, thoughtful emails, product descriptions |
| 5 | High (0.9) | Mid (0.9) | Mid (50) | Creative storytelling, idea generation, catchy copywriting |
| 6 | High (0.9) | High (0.98) | High (100) | Poetry, imaginative fiction, brainstorming wild ideas |
| 7 | Low (0.2) | High (0.95) | High (100) | Testing model edge behavior while keeping deterministic tone |
| 8 | High (0.8) | Low (0.8) | Mid (50) | Creative responses that stay grounded, metaphor-rich explanations |
- Read more: [[LLM Parameters]]
## **3. Core Prompting Techniques**
Prompting starts with mastering foundational techniques that gradually increase in complexity and reliability. The more structure you provide, the better the result.
### **Zero-Shot Prompting**
Zero-shot is the most basic form: you ask a question or give a task without providing any examples. This is effective for simple or well-known instructions.
**Use cases:**
- Basic classification (e.g., sentiment analysis)
- Quick factual queries
- Simple data transformation
**Pro Tips:**
- Be specific (e.g., “List 5 Border Collie health issues” vs. “Tell me about dogs”)
- Use clear action verbs: Analyze, Summarize, Classify
- One task per prompt
- Explicitly state output format
### **One-Shot Prompting**
One-shot includes a single example of how you want the model to respond. This is often the fastest way to improve accuracy.
**Use cases:**
- Specific formatting needs
- Ambiguous instructions
- Limited edge cases
**Benefits:**
- Models follow tone, formatting, and pattern better than with instructions alone
### **Few-Shot Prompting**
Few-shot prompting adds 3 - 5 examples to teach the model how to generalize. This is the gold standard for important or nuanced tasks.
**Use cases:**
- JSON generation
- Customer support replies
- Data extraction and transformation
**Tips:**
- Use diverse examples
- Keep formatting consistent
- Include reasoning when needed
- Order examples for progressive complexity
Choosing the Right Technique:
| Complexity | Technique |
| ---------- | --------- |
| Low | Zero-shot |
| Medium | One-shot |
| High | Few-shot |
#### **Other concepts good to know:
- **Step-back prompting** encourages the model to reflect on the broader context or goal before answering, promoting more thoughtful and context-aware responses.
- **Chain of Thought (CoT)** guides the model to reason step-by-step through a problem, improving performance on tasks requiring logical deduction.
- **Self-consistency** involves generating multiple responses and selecting the most consistent answer via majority voting, which increases output reliability and accuracy.
- **Tree of Thoughts (ToT)** enables the model to explore multiple reasoning paths in parallel, evaluating and expanding promising ones to solve complex problems.
- **ReAct** combines reasoning steps with external actions (e.g., tool use, web search), allowing the model to gather information and reason iteratively for better-informed outputs.
You can find more prompting techniques with detailed description here: [[Prompt Techniques]]
## **4. Prompt Frameworks**
A prompt framework helps you organize your thoughts and communicate them effectively to the model. Each framework is designed with a particular use case in mind - from creative writing and content generation to customer support and business reporting.
Examples of my favorite frameworks:
- **C.R.E.A.T.E (Character, Request, Examples, Adjustment, Type, Extras)**
- **M.I.N.D.S (Map, Investigate, Navigate, Develop, Sustain)**
- **S.O.L.V.E (Situation, Objective, Limitations, Vision, Execution)**
Other frameworks:
- **APE (Action, Purpose, Expectation)**: For content clarity and outcome expectations.
- **CARE (Context, Action, Result, Example)**: Ideal for UX flows.
- **COAST (Context, Objective, Action, Steps, Task)**: For instructional design.
- **ERA (Expectation, Role, Action)**: Great for precise output design.
- **GRWC (Goal, Return Format, Warnings, Context)**: Ensures clarity, constraints, and direction. Especially useful in business and legal contexts.
- **RACE (Role, Action, Context, Expectation)**: Versatile for conversations and planning.
- **RISE (Request, Input, Scenario, Expectation)**: Scenario-based simulation.
- **ROSES (Role, Objective, Steps, Expected output, Scenario)**: Support workflows.
- **TAG (Task, Action, Goal)**: For structured project guidance.
- **TRACE (Task, Role, Action, Context, Example)**: Branding, persuasive copy.
Each framework adds structure, intent, and consistency. Choose the one that best fits your goal.
- You can find more frameworks with detailed description here: [[Prompt Frameworks]]
## **4. Integrating Resources into Prompts**
Models thrive on structured information. Incorporating additional data into prompts helps narrow the scope of the model's response and enhance its factuality. These resources include embedded text, references, structured inputs, or examples.
- Include summaries, snippets, or structured data.
- Add content directly: quotes, JSON, or tables.
- Use citations or embedded reference material.
**Example:** "Based on the report below, generate an executive summary."
## **5. The Core Prompting Principles**
The following principles were derived from large-scale experimentation across models like GPT-4 and LLaMA-2. They are categorized into five areas to help you understand not just what to do, but why and how.
#### **Prompt Structure and Clarity**
1. **Be Direct** – Skip pleasantries like “please” or “thank you.” Be concise.
2. **Define the Audience** – Specify who the response is for (e.g., “Explain for a 5-year-old”).
3. **Decompose Tasks** – Break complex instructions into sequential steps.
4. **Use Positive Language** – Say “Do X” instead of “Don’t do Y.”
5. **Use Prompt Sections** – Structure prompts with `###Instruction###`, `###Example###`, `###Question###`.
6. **Add Leading Cues** – Use phrases like “Think step by step.”
7. **Use Delimiters** – Separate different parts of prompts clearly.
8. **Use Output Primers** – End with the beginning of the desired answer to nudge generation.
#### **Specificity and Information**
5. **Ask for Simplicity** – e.g., “Explain like I’m 5.”
6. **Use Few-shot Examples** – Show the model what kind of answers you expect.
7. **Add Unbiased Clause** – e.g., “Ensure answer is unbiased and free of stereotypes.”
8. **Request Teaching + Quiz** – e.g., “Teach me X and include a quiz at the end.”
9. **Request Detail** – e.g., “Write a detailed explanation with all relevant info.”
10. **Seed with Content** – Start a story, lyrics, or sentence and ask the model to continue.
11. **State Constraints** – Include explicit requirements, keywords, or formatting rules.
12. **Mimic a Style** – Ask for responses matching the style of provided text.
#### **User Interaction and Engagement**
14. **Enable Back-and-Forth** – Let the model ask you questions until it has enough info.
15. **Use Stakes Language** – Add playful prompts like “I’ll tip $300K for the best solution!”
#### **Content and Language Style**
16. _(again)_ – Be clear and skip social niceties.
17. **Add Mandatory Phrases** – Use “Your task is” or “You MUST.”
18. **Add Consequences** – “You will be penalized if…”
19. **Natural Language Output** – Ask for “human-like answers.”
20. **Assign a Role** – Define the LLM’s persona (e.g., “You are a legal analyst”).
21. **Use Repetition** – Repeat key words for emphasis or focus.
22. **Edit Without Changing Style** – Ask for grammar fixes but preserve tone.
#### **Complex Tasks and Coding Prompts**
23. _(again)_ – Split complex tasks into smaller steps.
24. **CoT + Few-shot** – Combine reasoning prompts with examples.
25. **Multi-file Coding Prompts** – Instruct model to generate scripts for multi-file outputs.
## **6. Iterative Development and Systematic Refinement**
Prompting isn’t a one-shot art. It’s an iterative science. Experts build and test variations across:
- Format
- Prompt structure
- Example diversity
- Output constraints
Example of an interatom table:
| | | | | |
| ------- | --------- | ----------------- | ----------- | ------------------ |
| Version | Technique | Key Change | Performance | Next Step |
| v1 | Zero-shot | Initial prompt | 5/10 | Add one-shot |
| v2 | One-shot | Example added | 7/10 | Add more examples |
| v3 | Few-shot | Diverse scenarios | 9/10 | Adjust temperature |
Track and document prompt versions to improve consistency, measure results, and scale solutions.
## **7. Additional Resources for Prompt Engineering**
### **Prompt Engineering, Google, 2025**
Here you can find some additional resources for Prompt Engineering:
![[Google_Prompt Engineering.pdf]]
"Google Prompt Engineering" by Lee Boonstra is an in-depth whitepaper that explores techniques, configurations, and best practices for designing effective prompts to guide large language models (LLMs), specifically within Google's Vertex AI ecosystem using the Gemini model. It aims to empower both technical and non-technical users to write prompts that yield accurate, relevant, and structured outputs. It presents a comprehensive methodology that emphasizes iterative experimentation, thoughtful configuration of model parameters, and structured prompt design to solve diverse tasks in natural language processing, code generation, reasoning, and more.
**Key Insights**
- **Prompt Engineering as Iterative Design**: Prompting is a non-linear, experimental process where clarity, context, structure, and examples are essential to guide LLMs effectively.
- **Model Configuration Matters**: Critical parameters such as output length, temperature, top-K, and top-P sampling control the randomness and creativity of the output. These should be tuned based on task specificity—deterministic outputs (e.g., math problems) require lower temperature, while creative tasks benefit from higher temperature.
- **Prompting Techniques**:
- **Zero-shot**, **one-shot**, and **few-shot** prompting vary in complexity, with examples enhancing model performance.
- **System prompting** sets overarching rules; **contextual prompting** adds task-specific data; **role prompting** defines personas for more tailored responses.
- Advanced strategies include:
- **Step-back prompting** to stimulate background reasoning.
- **Chain of Thought (CoT)** for stepwise logical reasoning.
- **Self-consistency** to enhance accuracy through sampling and majority voting.
- **Tree of Thoughts (ToT)** for branching reasoning.
- **ReAct** to integrate reasoning with external actions like API calls.
- **Code Prompting Use-Cases**: Includes writing, translating, explaining, and debugging code in Bash and Python, showcasing LLMs’ capabilities as developers’ assistants.
- **Automatic Prompt Engineering (APE)**: Automates prompt generation by leveraging LLMs to produce and refine prompts for tasks like chatbot training.
- **Best Practices**:
- Provide relevant, clear examples.
- Use specific instructions instead of negative constraints.
- Maintain prompt clarity, brevity, and focus.
- Use variables and structured formats (e.g., JSON) to increase reusability and consistency.
- Document every prompt iteration systematically, including model parameters and results.
**Actionable Takeaways**
- **Tune for Task**: Adjust temperature, top-K, and top-P based on whether the task is creative or deterministic. Default starting points are provided (e.g., temp 0.2/top-P 0.95 for balance).
- **Prompt Type Selection**:
- Use **few-shot prompting** with diverse examples for complex classification tasks.
- Apply **CoT** with temperature set to 0 for reasoning-heavy tasks.
- Implement **ReAct** for multi-step reasoning and tool use, such as querying search engines.
- **Adopt Schema-Based Structuring**:
- Use JSON for outputs to reduce hallucinations and increase clarity.
- Employ schemas for structured input to guide model interpretation.
- **Iterate & Document**: Track prompt performance in a structured template. Include prompt versions, outcomes, feedback, and hyperparameter settings for future refinements.
- **Collaborate and Evaluate**: Work with other prompt engineers, compare variations, and use metrics like BLEU or ROUGE for automatic evaluations.
### **Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4**
![[Principled Instructions.pdf]]
This paper presents a structured methodology to improve prompt engineering for large language models (LLMs) by introducing 26 principled instructions. The authors aim to demystify how users—both developers and laypersons - can generate better outputs from models like GPT-3.5/4 and LLaMA-1/2 through thoughtful prompting rather than model fine-tuning.
The study categorizes these principles across five key areas and validates their effectiveness through extensive experiments using the ATLAS benchmark across multiple LLM scales.
**Key Insights**
- **Prompt Engineering as Programming**: Prompts function as a programming interface for LLMs. Effective prompting can significantly boost the quality, correctness, and clarity of model responses.
- **Principle-Based Design**: The paper introduces 26 principles, grouped under five categories: Prompt Structure and Clarity, Specificity and Information, User Interaction and Engagement, Content and Language Style, and Complex Tasks and Coding Prompts.
- **Categories and Examples**:
- _Prompt Structure_: Use affirmatives, define audience, apply delimiters.
- _Specificity_: Ensure unbiased responses, mimic example styles, provide clear expectations.
- _Engagement_: Let the model ask for clarification, provide feedback loops.
- _Content Style_: Drop politeness, assign roles, emphasize directness.
- _Coding/Complex Tasks_: Use multi-step prompting, chain-of-thought reasoning, auto-code generation.
- **Design Principles**: Effective prompts are concise, contextually grounded, task-aligned, unbiased, and often benefit from being stepwise or iterative.
- **Empirical Results**: Incorporating these principles leads to significant performance improvements. GPT-4 showed a 57.7% average quality improvement and 67.3% accuracy gain, with larger models generally benefiting more than smaller ones.
- **Generalizability**: While effective across major LLMs, the principles may vary in efficacy with unseen model architectures or domain-specific questions.
**Actionable Takeaways**
- Use prompts that explicitly define the audience and purpose.
- Avoid redundant politeness; be direct and informative.
- Break down complex questions into simpler steps for better responses.
- Use examples and templates to structure prompts.
- Incorporate meta-language like “Your task is…” or “You must…” to direct model behavior.
- Allow the model to iteratively refine its output by requesting more information when necessary.
- Employ prompt formatting with labeled sections (e.g., `###Instruction###`, `###Example###`).
- Combine prompting strategies (e.g., few-shot with chain-of-thought) for challenging tasks.
- Use output priming by beginning the desired format in the prompt.
### **Prompt Engineering Guide by DAIR.AI**
A comprehensive and curated collection of prompt engineering techniques, tools, and examples for working with large language models.
- GitHub: [https://github.com/dair-ai/Prompt-Engineering-Guide](https://github.com/dair-ai/Prompt-Engineering-Guide)
### **Other resources**
- OpenAI: [GPT-4.1 Prompting Guide](https://cookbook.openai.com/examples/gpt4-1_prompting_guide)
- OpenAI: [Enhance your prompts with meta prompting](https://cookbook.openai.com/examples/enhance_your_prompts_with_meta_prompting)
- Antropic: [Prompt engineering overview](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview)
- Antropic: [Extended thinking tips](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/extended-thinking-tips)
- Antropic: [Prompt Engineering Interactive Tutorial](https://github.com/anthropics/prompt-eng-interactive-tutorial)
- Hugging Face: [Prompt Engineering](https://huggingface.co/docs/transformers/tasks/prompting)