explaingit

dair-ai/prompt-engineering-guide

74,723MDXAudience · developerComplexity · 1/5MaintainedLicenseSetup · easy

TLDR

A comprehensive guide teaching techniques to write better instructions for AI language models like ChatGPT, improving output quality and reliability.

Mindmap

mindmap
  root((Prompt Engineering Guide))
    Fundamentals
      Prompt structure
      Clarity tips
      Element selection
    Core Techniques
      Zero-shot prompting
      Few-shot prompting
      Chain-of-Thought
    Advanced Methods
      Tree of Thoughts
      ReAct reasoning
      RAG retrieval
    Practical Applications
      Code generation
      Data generation
      Classification tasks
    Safety & Risks
      Prompt injection
      Attack prevention
      Mitigation strategies

Things people build with this

USE CASE 1

Learn step-by-step techniques to get better answers from ChatGPT, Claude, or other AI models.

USE CASE 2

Build applications that reliably extract structured data or generate code using language models.

USE CASE 3

Understand how to defend against prompt injection attacks when deploying AI-powered systems.

USE CASE 4

Improve accuracy on complex reasoning tasks by applying Chain-of-Thought and Tree of Thoughts methods.

Tech stack

MDXMarkdownReact

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose including commercial, as long as you keep the copyright notice.

In plain English

The Prompt Engineering Guide is a comprehensive educational resource that teaches people how to write better instructions for large language models, AI systems like ChatGPT, Claude, or Llama. The core problem is that these models are extremely sensitive to how you phrase a request: the same question worded differently can produce dramatically better or worse results. Prompt engineering is the skill of crafting those instructions deliberately to get reliable, high-quality outputs. The guide covers a wide spectrum of techniques with increasing sophistication. It starts with the basics, how to structure a prompt, what elements it should contain, and general tips for clarity. It then progresses to named techniques that researchers have developed: zero-shot prompting (asking the model to do something with no examples), few-shot prompting (giving it a small number of examples first), and Chain-of-Thought prompting (asking the model to reason step-by-step before answering, which dramatically improves accuracy on complex problems). More advanced topics include Tree of Thoughts (exploring multiple reasoning paths simultaneously), ReAct (combining reasoning with tool use), and Retrieval-Augmented Generation, known as RAG, where external documents are fed to the model alongside the question to improve factual accuracy. The guide also covers risks such as prompt injection, a type of attack where malicious text in the input hijacks the model's behavior, and covers practical applications in coding, data generation, and classification tasks. You would use this guide if you work with or build applications on top of large language models and want to get more reliable, precise outputs. Researchers, developers, and non-technical users who regularly use AI tools can all benefit. The content is written in MDX (Markdown with embedded components), which is a format used to build documentation websites.

Copy-paste prompts

Prompt 1
Show me examples of zero-shot vs few-shot prompting from the Prompt Engineering Guide and explain when to use each.
Prompt 2
How do I use Chain-of-Thought prompting to improve accuracy on math and logic problems with language models?
Prompt 3
What is Retrieval-Augmented Generation (RAG) and how does it help language models give more factually accurate answers?
Prompt 4
Give me a prompt injection attack example and explain how to defend against it based on the guide's security section.
Prompt 5
Walk me through the ReAct technique for combining reasoning with tool use in language model applications.
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.