# Prompt Engineering Guide — User Guide

The Prompt Engineering Guide by DAIR.AI is a comprehensive, open-source knowledge base covering techniques, research, applications, and best practices for working with large language models (LLMs). It serves as both a learning resource for newcomers and a reference for practitioners who need to understand the full landscape of prompt engineering — from basic zero-shot prompting through advanced agent architectures.

## 1. Quick Start

### What You Get

The Prompt Engineering Guide is a web-based documentation site with:

- **18 prompting techniques** explained with examples and research citations
- **20+ model-specific guides** covering ChatGPT, GPT-4, Claude 3, Gemini, LLaMA, Mistral, and more
- **Prompt Hub** with ready-to-use prompts across 12 task categories
- **AI Agents** section covering agent components, workflows, context engineering, and function calling
- **13 Jupyter notebooks** for hands-on experimentation
- **14 language translations** for global accessibility
- **AI integration features** — copy any page as markdown for use in Claude or ChatGPT

### Accessing the Guide

Open the site in any web browser. No installation, account, or API key required.

> [!TIP]
> Start with the **Introduction** section if you are new to prompt engineering, or jump directly to **Prompting Techniques** if you already understand the fundamentals of working with LLMs.

### What to Read First

| Your Goal | Start Here |
|-----------|------------|
| Learn prompt engineering from scratch | Introduction > Basics of Prompting |
| Improve output quality on a specific task | Prompting Techniques > pick the relevant technique |
| Find ready-to-use prompts | Prompt Hub > pick your task category |
| Understand a specific LLM's strengths | Models > pick your model |
| Build AI agents | AI Agents > Introduction to Agents |
| Hands-on coding practice | Notebooks |

## 2. Navigating the Guide

### Site Structure

The guide is organized into top-level sections accessible from the left sidebar:

| Section | What's Inside |
|---------|--------------|
| **Introduction** | LLM settings, basics of prompting, prompt elements, design tips, examples |
| **Prompting Techniques** | 18 documented techniques with theory, examples, and citations |
| **AI Agents** | Agent components, workflows vs. agents, context engineering, function calling, deep agents |
| **Guides** | Topical deep-dives (GPT-4o image generation, context engineering, deep research, reasoning LLMs, optimizing prompts) |
| **Applications** | Practical use cases (code generation, data generation, function calling, context caching, fine-tuning) |
| **Prompt Hub** | Categorized prompt examples across 12 task types |
| **Models** | Model-specific guides for 20+ LLMs |
| **Risks & Misuses** | Adversarial prompting, factuality issues, biases |
| **LLM Research Findings** | Research summaries on RAG, reasoning, tokenization, trustworthiness, and more |
| **Papers** | Curated list of relevant research papers |
| **Tools** | External tools and libraries for prompt engineering |
| **Notebooks** | Jupyter notebooks for hands-on practice |
| **Datasets** | Datasets relevant to prompt engineering research |
| **Additional Readings** | Further resources and references |

### Multilingual Support

The guide is available in 14 languages. Switch languages using the language selector in the top navigation bar.

| Language | Code |
|----------|------|
| English | `en` |
| Chinese (中文) | `zh` |
| Japanese (日本語) | `jp` |
| Portuguese (Português) | `pt` |
| Italian | `it` |
| Turkish (Türkçe) | `tr` |
| Spanish (Español) | `es` |
| French (Français) | `fr` |
| Korean (한국어) | `kr` |
| Catalan (Català) | `ca` |
| Finnish | `fi` |
| Russian (Русский) | `ru` |
| German (Deutsch) | `de` |
| Arabic (العربية) | `ar` |

> [!NOTE]
> Not all pages are translated into every language. English has the most complete coverage, including the AI Agents and Guides sections which are English-only. Other languages cover the core Introduction, Techniques, Applications, Models, Risks, and Research sections.

### Search

Use the search bar at the top of the page to find content across all sections. Type any keyword and results appear instantly.

## 3. Introduction to Prompt Engineering

The Introduction section covers the foundational concepts you need before diving into specific techniques.

### LLM Settings

Understanding key parameters that control LLM behavior:

- **Temperature** — controls randomness in output. Lower values (e.g., 0.1) produce more deterministic responses; higher values (e.g., 0.9) produce more creative, varied output
- **Top-p (nucleus sampling)** — an alternative to temperature that limits the token pool to those whose cumulative probability reaches a threshold
- **Max tokens** — controls the maximum length of the generated response
- **Frequency penalty / Presence penalty** — control repetition in outputs

### Basics of Prompting

Core concepts including how to write effective prompts, the difference between instructions and context, and how to structure requests for optimal results.

### Prompt Elements

The four key elements that make up a prompt:

- **Instruction** — the specific task you want the model to perform
- **Context** — external information or additional detail that steers the model
- **Input Data** — the input or question you are asking about
- **Output Indicator** — the type or format of the desired output

### General Tips for Designing Prompts

Practical advice for writing better prompts, including strategies for specificity, iteration, and avoiding common mistakes.

### Examples of Prompts

Worked examples demonstrating prompt engineering principles across summarization, question answering, classification, code generation, and reasoning tasks.

> [!TIP]
> The Introduction section uses progressive examples — each concept builds on the previous one. Reading them in order gives you the strongest foundation.

## 4. Prompting Techniques

This is the core of the guide. Each technique has its own dedicated page with an explanation of how it works, when to use it, example prompts, expected outputs, and research citations.

### Technique Overview

| Technique | Key Idea | Best For |
|-----------|----------|----------|
| **Zero-shot Prompting** | Prompt without examples | Simple tasks where the model has strong prior knowledge |
| **Few-shot Prompting** | Provide examples in the prompt | Tasks needing demonstration of desired format or behavior |
| **Chain-of-Thought (CoT)** | Ask the model to reason step by step | Math, logic, multi-step reasoning |
| **Meta Prompting** | Use a meta-prompt to generate or refine prompts | Prompt optimization and automated prompt engineering |
| **Self-Consistency** | Sample multiple reasoning paths, take majority vote | Improving accuracy on reasoning tasks |
| **Generate Knowledge Prompting** | Generate relevant knowledge before answering | Knowledge-intensive tasks |
| **Prompt Chaining** | Break complex tasks into sequential sub-prompts | Multi-step workflows, document processing |
| **Tree of Thoughts (ToT)** | Explore multiple reasoning branches | Complex problem solving requiring exploration |
| **Retrieval Augmented Generation (RAG)** | Combine retrieval with generation | Grounding responses in external knowledge |
| **Automatic Reasoning and Tool-use (ART)** | Automatic CoT + tool selection | Tasks requiring both reasoning and external tools |
| **Automatic Prompt Engineer (APE)** | Automatically generate and select prompts | Optimizing prompts at scale |
| **Active-Prompt** | Adapt CoT examples to specific tasks | Domain-specific reasoning tasks |
| **Directional Stimulus Prompting (DSP)** | Use a hint/cue to guide generation | Summarization, dialogue |
| **Program-Aided Language Models (PAL)** | Generate code to solve problems | Math and logical reasoning |
| **ReAct** | Combine reasoning traces with actions | Tasks requiring interaction with external tools/APIs |
| **Reflexion** | Use self-reflection to improve outputs | Iterative improvement, coding, decision-making |
| **Multimodal CoT** | Apply chain-of-thought to multimodal inputs | Vision + language reasoning |
| **Graph Prompting** | Structure prompts as graphs | Relationship-heavy reasoning tasks |

> [!IMPORTANT]
> Techniques are not mutually exclusive. Many real-world applications combine multiple approaches — for example, using RAG with CoT prompting, or combining Few-shot with Self-Consistency.

### How to Choose a Technique

Start with the simplest approach and add complexity only as needed:

1. **Try zero-shot first** — if the model produces good results without examples, you are done
2. **Add few-shot examples** if the output format or quality needs guidance
3. **Add chain-of-thought** if the task requires multi-step reasoning
4. **Use self-consistency** if accuracy is critical and you can afford multiple samples
5. **Use RAG** if the task requires information the model does not have in its training data
6. **Use ReAct or ART** if the task requires interacting with external tools or APIs

> [!WARNING]
> More complex techniques consume more tokens and increase latency. Always measure whether the added complexity actually improves your results before adopting it in production.

## 5. AI Agents

The AI Agents section is a dedicated area covering the design and implementation of LLM-powered autonomous agents.

### Topics Covered

| Page | What You Learn |
|------|---------------|
| **Introduction to Agents** | What AI agents are, how they differ from simple LLM calls, core concepts |
| **Agent Components** | Memory, planning, tool use, and perception — the building blocks of agents |
| **AI Workflows vs AI Agents** | When to use deterministic workflows vs. autonomous agents, design patterns including prompt chaining, routing, parallelization, and orchestrator-worker |
| **Context Engineering for AI Agents** | How to design the information environment for effective agent performance |
| **Context Engineering Deep Dive** | Advanced patterns for managing agent context at scale |
| **Function Calling** | How agents interact with external APIs and tools through structured function calls |
| **Deep Agents** | Advanced multi-agent systems and deep research patterns |

> [!TIP]
> If you are building production AI agents, read the **Context Engineering** pages carefully. Effective context management is often the difference between agents that work reliably and those that fail unpredictably.

## 6. Applications

Practical, task-oriented guides showing prompt engineering applied to real-world problems.

### Available Application Guides

| Application | Description |
|-------------|-------------|
| **Fine-tuning GPT-4o** | How to fine-tune OpenAI's GPT-4o model for specific tasks |
| **Function Calling** | Implementing structured tool use with LLMs |
| **Context Caching with LLMs** | Reducing costs and latency through context caching |
| **Generating Data** | Using LLMs to generate training data, test data, and synthetic datasets |
| **Generating Synthetic Dataset for RAG** | Creating domain-specific datasets for retrieval-augmented generation |
| **Tackling Generated Datasets Diversity** | Ensuring diversity and quality in AI-generated datasets |
| **Generating Code** | Code generation techniques and best practices |
| **Graduate Job Classification Case Study** | Real-world classification task walkthrough |
| **Prompt Function** | Treating prompts as reusable functions with inputs and outputs |

## 7. Prompt Hub

The Prompt Hub is a curated collection of ready-to-use prompt examples organized by task type. Each entry includes the prompt template and expected output.

### Categories

| Category | Example Tasks |
|----------|--------------|
| **Classification** | Sentiment analysis (zero-shot and few-shot) |
| **Coding** | Code snippets, MySQL queries, TikZ diagrams |
| **Creativity** | Infinite primes proof, interdisciplinary connections, new words, rhymes |
| **Evaluation** | Plato dialogue evaluation |
| **Information Extraction** | Extracting model names and details from text |
| **Image Generation** | Alphabet person prompt |
| **Mathematics** | Composite functions, odd numbers addition |
| **Question Answering** | Closed-domain, open-domain, science QA |
| **Reasoning** | Indirect reasoning, physical reasoning |
| **Text Summarization** | Concept explanation |
| **Truthfulness** | Identifying hallucinations |
| **Adversarial Prompting** | Jailbreaking attempts, prompt injection, prompt leaking |

> [!NOTE]
> The Adversarial Prompting category exists for educational purposes — understanding attack vectors is essential for building robust LLM applications.

## 8. Models

The Models section provides model-specific prompting guides. Each guide covers the model's capabilities, strengths, limitations, and effective prompting strategies.

### Covered Models

| Provider | Models |
|----------|--------|
| **OpenAI** | ChatGPT, GPT-4, Sora |
| **Anthropic** | Claude 3 |
| **Google** | Gemini, Gemini Advanced, Gemini 1.5 Pro, Gemma |
| **Meta** | LLaMA, Llama 3, Code Llama |
| **Mistral AI** | Mistral 7B, Mistral Large, Mixtral, Mixtral 8x22B |
| **Google (Flan)** | Flan |
| **AI2** | OLMo |
| **Microsoft** | Phi-2 |
| **xAI** | Grok-1 |
| **Moonshot AI** | Kimi K2.5 |
| **Collection** | Comprehensive list of available LLMs |

> [!TIP]
> The **LLM Collection** page provides a comprehensive overview of many models beyond those with dedicated guides, making it a useful starting point if you are evaluating which model to use.

## 9. Risks and Misuses

Understanding the risks associated with LLM usage is critical for responsible deployment.

### Topics

- **Adversarial Prompting** — how attackers can manipulate LLM behavior through prompt injection, jailbreaking, and prompt leaking
- **Factuality** — understanding and mitigating hallucination, fabricated citations, and confidently wrong outputs
- **Biases** — recognizing and addressing biases in LLM outputs, including stereotypes, demographic biases, and cultural assumptions

> [!WARNING]
> If you are building user-facing LLM applications, the Risks section is required reading. Adversarial prompting attacks are a real and evolving threat.

## 10. Research Findings

Summaries of key research relevant to prompt engineering and LLM capabilities.

| Topic | Key Insight |
|-------|-------------|
| **LLM Agents** | Survey of agent architectures and capabilities |
| **RAG for LLMs** | Framework, paradigms, and optimization strategies for retrieval-augmented generation |
| **LLM Reasoning** | Current state and limitations of reasoning in LLMs |
| **RAG Faithfulness** | Measuring and improving how faithfully RAG systems use retrieved context |
| **LLM In-Context Recall** | How well models recall information provided in context |
| **RAG Reduces Hallucination** | Evidence that retrieval augmentation reduces fabrication |
| **Synthetic Data** | Generating and using synthetic training data |
| **ThoughtSculpt** | A framework for reasoning refinement |
| **Infini-Attention** | Scaling attention to infinite context lengths |
| **LM-Guided CoT** | Using language models to guide chain-of-thought reasoning |
| **Trustworthiness in LLMs** | Dimensions of trust — truthfulness, safety, fairness, robustness, privacy, and ethics |
| **LLM Tokenization** | How tokenization affects model behavior |
| **What is Groq?** | Groq's LPU inference architecture and performance |

## 11. AI-Powered Features

The guide includes built-in features that integrate with AI assistants.

### Copy Page as Markdown

On English pages, a **Copy page** dropdown appears in the top-right area of the content. This provides three options:

| Option | What It Does |
|--------|-------------|
| **Copy page** | Copies the current page content as clean markdown (imports and frontmatter stripped), ready to paste into any LLM |
| **Open in Claude** | Opens Claude with a pre-filled prompt to read and discuss the current page |
| **Open in ChatGPT** | Opens ChatGPT with a pre-filled prompt to read and discuss the current page |

> [!TIP]
> Use **Copy page** to feed prompt engineering content directly into your LLM conversations. This is especially useful for combining technique descriptions with your own task-specific prompts.

### LaTeX Support

The guide renders mathematical notation using KaTeX. Mathematical formulas appear throughout the research and techniques sections where formal notation improves clarity.

## 12. Notebooks

The guide includes 13 Jupyter notebooks for hands-on learning:

| Notebook | Topic |
|----------|-------|
| `pe-chatgpt-intro.ipynb` | Introduction to prompting with ChatGPT |
| `pe-chatgpt-adversarial.ipynb` | Adversarial prompting experiments |
| `pe-chatgpt-langchain.ipynb` | Using LangChain with ChatGPT |
| `pe-code-llama.ipynb` | Code Llama prompting |
| `pe-function-calling.ipynb` | Function calling implementation |
| `pe-lecture.ipynb` | Lecture companion notebook |
| `pe-litellm-intro.ipynb` | Introduction to LiteLLM |
| `pe-mixtral-introduction.ipynb` | Mixtral prompting guide |
| `pe-pal.ipynb` | Program-Aided Language Models |
| `pe-rag.ipynb` | RAG implementation |
| `react.ipynb` | ReAct framework implementation |
| `gemini-context-caching.ipynb` | Gemini context caching |

> [!NOTE]
> Notebooks require Python and the relevant API keys (OpenAI, Google, etc.) to run. Install dependencies as specified in each notebook.

## 13. Courses and Learning Paths

DAIR.AI offers structured courses through their Academy platform for deeper learning:

| Course | Focus |
|--------|-------|
| Intro to Prompt Engineering | Foundations of prompt engineering |
| Advanced Prompt Engineering | Advanced techniques and strategies |
| Intro to AI Agents | Building AI agent systems |
| Building Effective AI Agents with n8n | Practical agent building with n8n |
| Build RAG Systems | RAG implementation and optimization |
| Building Advanced AI Agents | Advanced multi-agent architectures |

Courses are available at [academy.dair.ai](https://academy.dair.ai/courses).

## 14. Community

- **GitHub** — contribute, report issues, or suggest content at the project repository
- **Discord** — join the community for discussions and support

## 15. Troubleshooting

### Search returns no results

**Cause:** The search indexes page titles and content, but may not cover all nested subpages.

**Solution:** Try broader search terms, or navigate the sidebar directly. Content within code blocks and image captions may not be indexed.

### Page not available in my language

**Cause:** Translation coverage varies by language. English has the most complete content.

**Solution:** Switch to English using the language selector. Some sections (AI Agents, Guides) are English-only.

### Copy page button not visible

**Cause:** The Copy page dropdown only appears on English pages (not the homepage).

**Solution:** Switch to the English locale and navigate to a content page.

**Prevention:** The feature is designed to work with the English content pipeline. Non-English pages use different content structures.

### Notebook fails to run

**Cause:** Missing API keys or dependencies.

**Solution:**
1. Check that Python is installed
2. Install required packages listed in the notebook's first cells
3. Set required API keys as environment variables (e.g., `OPENAI_API_KEY`)
4. Ensure your API key has sufficient quota

### Mathematical formulas not rendering

**Cause:** KaTeX rendering requires JavaScript to be enabled.

**Solution:** Ensure JavaScript is enabled in your browser. If using a content blocker, whitelist the site.

## 16. FAQ

**Q: Do I need any programming experience to use this guide?**

No. The conceptual content (techniques, models, risks) is accessible without programming knowledge. The Notebooks and some Application guides assume Python familiarity.

**Q: How often is the guide updated?**

The guide is actively maintained and updated as new models, techniques, and research emerge. Each page shows its last updated date at the bottom.

**Q: Can I contribute to the guide?**

Yes. The project is open-source on GitHub. You can contribute translations, fix errors, add new content, or suggest improvements through pull requests and issues. See the repository for contribution guidelines.

**Q: Which technique should I start with?**

Start with Zero-shot Prompting. If results are insufficient, try Few-shot Prompting. For reasoning tasks, add Chain-of-Thought. The Prompting Techniques section is ordered from simplest to most complex.

**Q: Is this guide specific to OpenAI models?**

No. While many examples use ChatGPT/GPT-4 for illustration, the techniques are model-agnostic. The Models section covers 20+ models from multiple providers, and the principles apply broadly.

**Q: How do I cite this guide?**

The repository includes a `CITATION.cff` file. Use it for academic citations. The guide is maintained by DAIR.AI.

**Q: What is the Prompt Hub?**

The Prompt Hub is a collection of categorized, ready-to-use prompt templates. Each prompt includes the task description, the prompt itself, and the expected output format. Think of it as a cookbook of proven prompt patterns.

**Q: Can I use the guide content in my own projects?**

The guide is released under the MIT License. See the `LICENSE.md` file in the repository for full terms.

---

_Generated May 2026 from dair-ai/Prompt-Engineering-Guide at 5767372. AI-generated documentation. The library is checked by sampling (three repositories so far); this guide was not individually reviewed. Verify against the project before relying on it. Unofficial; not affiliated with or reviewed by the project._
