Prompt Engineering Guide
A free prompt engineering guide for ChatGPT, Claude and Gemini: how to write a prompt, the core techniques, prompts for coding, and where models fail. Every prompt on these pages is editable and opens in your own AI app.
Start a guided AI Prompts journeyGetting Started
- What Is a PromptA prompt is the text you give an AI model to tell it what to produce. See what goes into one, real prompts for text, code and images, and how a prompt differs from the reply and the system prompt.
- Prompt EngineeringPrompt engineering is the practice of writing and testing the instructions you give an AI model so it produces the output you need. This guide explains why it works and maps every core technique.
- How to Write a PromptA good prompt is a short brief: a role, a task, the context the model cannot guess, the material to work on, the shape of the answer and the limits. Each part fixes a different way an answer goes wrong.
- Prompt ExamplesThirteen copy-ready prompts for learning, coding, writing and planning. Fill in the blanks, then copy the prompt or open it in ChatGPT or Claude.
- System PromptA system prompt is a set of standing instructions that applies to a whole conversation with an AI model. Learn where it lives, what to put in it, and how it differs from a user message.
- Tokens and ContextAI models read text as tokens, small chunks of words, and can only hold a limited number of them at once: the context window. Learn how both work and what to do when a chat gets long.
- TemperatureTemperature controls how much randomness a language model uses when it picks each next word. See how it reshapes the odds of each word, when to set it low or high, and how it differs from top_p.
Core Techniques
- Zero-Shot PromptingZero-shot prompting means asking a model to do a task from instructions alone, with no examples of the answer. It is how most people use ChatGPT, Claude and Gemini, and it works well when the task is common and the instruction is precise.
- Few-Shot PromptingFew-shot prompting puts a few worked examples, each an input and the answer you want, into the prompt so the model copies the pattern. It is the quickest way to teach a format, a label set or a house style the model would not guess.
- Chain of ThoughtChain of thought prompting asks a model to write out its reasoning before it gives the answer. It helps most on multi-step math and logic problems, and matters less for reasoning models that already think before they answer.
- Role PromptingRole prompting gives the model a part to play, such as a tutor, a code reviewer or an interviewer. A role changes who the answer is written for and what standard it meets; it does not add knowledge the model lacks.
- Structured OutputStructured output means asking the model for an answer in a fixed shape, such as JSON, a table or a template, so a program or a person can use it without reshaping it. Give the schema, say what to do with missing values, and validate the result in code.
- Delimiters and XML TagsDelimiters mark where pasted material starts and ends, so the model can tell your instructions from the text it should work on. Quotes, triple backticks, ### lines and XML tags all work; XML tags scale best when a prompt holds several pieces of material.
- Prompt TemplatesA prompt template is a prompt you have already tested, with blanks for the parts that change each time. Copy ready-made templates with fill-in fields, then turn your own best prompt into one in five steps.
Advanced Techniques
- Prompt ChainingPrompt chaining splits a job into a sequence of smaller prompts, where the output of each step becomes the input of the next. Each step does one thing, and you can check its result before the next one runs.
- Self-ConsistencySelf-consistency prompting asks the same reasoning question several times, lets each run reason its own way, and keeps the answer that comes up most often. Here is how it works, how to do it by hand, and how to do it in code.
- Tree of ThoughtTree of thought prompting has the model explore several partial solutions, judge each one, and keep only the promising branches. Here is how the original method works, a one-prompt version you can try, and where that version falls short.
- ReAct PromptingReAct prompting makes a model alternate between reasoning about a task and calling a tool, reading each result before it decides the next step. It is the loop behind most AI agents.
- Meta PromptingMeta prompting means using a model to work on prompts: writing one from scratch, improving one you have, or splitting a task into prompts for other model calls. Here is how to do each without getting a bloated prompt back.
- Context EngineeringContext engineering is deciding everything that goes into a model's context window on each call: instructions, documents, tool results, memory and conversation history, and the order they come in. The prompt you type is only one part.
Prompting for Code
- Prompts for Writing CodeCoding prompts work when they read like a small spec: the language and version, the inputs and outputs, the edge cases, and the tests the code must pass. Ask for one small step at a time.
- Prompts for DebuggingTo debug with ChatGPT or Claude, paste the full error and the code that raised it, say what you expected and what happened instead, list what you already tried, and ask for the cause before the fix.
- Explaining CodeAsk AI to explain code line by line, at your level, with a table of how the values change as it runs. Say what you already know so the explanation starts where you are.
- Prompts for Code ReviewA good code review prompt says what to look for, asks for a severity on every finding, wants a concrete failing input and a diff, and tells the model to skip style. Then you check each finding, because some will be wrong.
Limits and Safety
- AI HallucinationAn AI hallucination is a confident answer that is false: an invented fact, citation, function or package. It happens because a language model predicts likely text instead of looking anything up. Prompts can reduce it; only checking catches it.
- Prompt InjectionPrompt injection is an attack where text the model reads, typed by a user or hidden in an email, web page or file, overrides the instructions the application gave it. Delimiters help but do not stop it; limiting what the model can do does.
- Iterating on PromptsImproving a prompt works best as a small experiment: decide what a good answer looks like, keep a few fixed test inputs, change one thing at a time and compare the outputs side by side.