Prompt Engineering

Prompt engineering is the practice of carefully crafting the text instructions you give to an AI language model in order to reliably get the response you want. It matters because the same AI model can produce wildly different outputs depending on how a question is phrased — making it less like programming a computer and more like communicating skillfully with a very well-read but literally-minded colleague. The counterintuitive fact: a single extra sentence in your prompt can sometimes improve an AI's accuracy by 30% or more, with no changes to the model itself.

The core insight

The "aha moment" is this: an AI language model is not a search engine you query, nor a calculator you program — it is a pattern-completing machine that you steer through language. The words you choose, the examples you include, the role you assign, and even the order you present information all shape which pattern the model completes. Prompt engineering is simply the craft of learning which steering moves work reliably, and why. Once you see prompts as a steering wheel rather than a command line, everything about how to write them changes.

How It Works

When you type a prompt into a system like ChatGPT or Claude, the model does not "understand" it the way a person would. Instead, it reads your words as a sequence of tokens — small chunks of text — and predicts, one piece at a time, what text should come next based on everything it learned during training. Your prompt is essentially the opening of a story, and the model completes it. This means every element of your prompt is a clue about which kind of completion should follow. There are several core mechanisms at play:

Context Setting is the practice of telling the model who it is and what situation it is in before asking anything. If you begin with "You are a friendly doctor explaining things to a patient," the model's completions will be drawn from a very different pool of patterns than if you begin with "You are a lawyer writing a formal brief." The role you assign acts like a costume that shapes every word that follows.

Instruction Clarity means giving the model an unambiguous task. Vague instructions like "help me with this email" activate a wide fan of possible completions. Specific instructions like "rewrite this email to be more concise, under 100 words, maintaining a professional tone" narrow the fan dramatically.

Few-Shot Examples are perhaps the most powerful basic technique. Instead of only describing what you want, you show the model two or three examples of input-output pairs before giving it the real input. The model recognizes the pattern of your examples and applies it to the new case — like showing a new employee three completed expense reports before asking them to fill out a fourth.

Chain-of-Thought Prompting asks the model to reason out loud before giving its final answer, typically by adding a phrase like "Think step by step." This works because reasoning through intermediate steps activates patterns associated with careful, accurate problem-solving rather than patterns associated with quick, confident answers that can be wrong.

Output Formatting Instructions tell the model exactly how to structure its response — "give me a numbered list," "respond in JSON," "write exactly three bullet points." Models are extremely responsive to these because formatting is one of the most strongly patterned features in training data.

researcher · Jason Wei | b. 1996 | Chain-of-Thought Prompting

Jason Wei is a researcher at Google Brain and later OpenAI who co-authored the landmark 2022 paper introducing chain-of-thought prompting — the discovery that asking a model to show its reasoning steps dramatically improves accuracy on complex problems. His work revealed that this capability emerges suddenly in very large models, being nearly absent in smaller ones, which became one of the key examples of what researchers call "emergent abilities." Surprisingly, the phrase "Let's think step by step" — one of the most studied strings in AI research — was not in the original chain-of-thought paper but was popularized in a concurrent paper by Kojima et al., leading to a friendly priority debate in the research community.

Figure
Prompt Engineering: How a Prompt Shapes the Output
How Prompt Structure Steers Model Output YOUR PROMPT Role / Persona Context / Background Examples (Few-Shot) Clear Instruction Format Spec Language Model Vague Prompt → Generic / Off-target output Engineered Prompt → Precise, useful output ✓ No Examples → Unpredictable format Prompt structure selects which learned patterns fire

Intuition

The Mental Model

Think of a large language model as an extraordinarily well-read library intern who has read essentially everything ever published but has no personal memory, no common sense from lived experience, and no way to ask you a follow-up question. When you hand them a note, they will do their absolute best to respond in a way that fits the pattern of notes like yours. If your note is ambiguous, they will pick the most statistically common interpretation — which may not be yours. Prompt engineering is the skill of writing that note well. Here is the most useful analogy: imagine you are directing an actor who has memorized every script ever written and can play any role perfectly — but only if you tell them clearly which role to play and what scene you are in. If you walk up and say "say something funny," they might launch into a Shakespearean comedy monologue when you wanted a one-liner. But if you say "you are a stand-up comedian doing a tight five for a corporate audience, give me three clean office jokes," they will nail it. The few-shot technique has its own analogy: it is like training a new employee not by writing a policy manual, but by showing them three completed examples of the exact kind of work you need. Humans learn by example far faster than by abstract description, and language models work almost identically in this respect. Chain-of-thought prompting is like asking someone to show their work on a math test. The act of writing down intermediate steps forces a more careful, structured process — and the same is true for AI. The model is less likely to jump to a confidently wrong answer when it must narrate the path it took to get there. Finally, think of the system prompt — the invisible instructions many AI products use before you ever type a word — as the costume, set, and director's notes given to the actor before the audience arrives. The user's message is just the first line of dialogue in an already-staged scene.

Historical Development

Origins · 1 minhow this was discovered
History
2017
The Transformer architecture (Vaswani et al., "Attention Is All You Need") creates the model type for which prompt engineering would become relevant — text-in, text-out at scale.
2019
GPT-2 (OpenAI) demonstrates that large language models can follow simple natural-language instructions without any task-specific training, hinting that prompting could substitute for fine-tuning.
2020
GPT-3 (Brown et al., OpenAI) introduces the term "few-shot learning" into mainstream AI discourse and shows that providing examples directly in the prompt dramatically improves performance — the first systematic demonstration of in-context learning.
2021
The term "prompt engineering" enters widespread use among practitioners; early communities on Twitter and Reddit begin systematically cataloguing which prompt structures work and why.
2022
Wei et al. (Google Brain) publish "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models," establishing the most influential single prompting technique and spawning a wave of follow-on research.
2022
OpenAI launches ChatGPT (November), bringing prompt engineering into mainstream public consciousness as millions of non-technical users begin experimenting with prompt phrasing on their own.
2023
The concept of "prompt injection" — malicious text designed to override a model's instructions — is formally studied as a security risk, showing that prompt engineering has adversarial implications as well as constructive ones.
2023
Frameworks for agentic systems (LangChain, AutoGPT) popularize "meta-prompting" — using AI to write and refine prompts automatically, beginning the transition from human prompt craft to automated prompt optimization.
2024
Research into "prompt compression" and "prompt caching" emerges as models with very long context windows make prompt efficiency an economic and performance concern, not just a craft concern.

Why It Matters

Real-World Impact
ChatGPT and Claude (Customer-Facing Products)These products use carefully engineered system prompts — invisible to users — that define the assistant's persona, safety guidelines, response style, and capabilities. The entire user experience is shaped by prompt engineering before the user types a single word.
GitHub Copilot (Code Assistance)Copilot constructs prompts dynamically by combining the user's current file, surrounding code context, and comments — engineering a prompt behind the scenes so that the model suggests the next logical lines of code. The quality of suggestions depends almost entirely on how well this automatic prompt is assembled.
RAG Systems (Retrieval-Augmented Generation)In Retrieval-Augmented Generation pipelines, retrieved documents are inserted into a prompt alongside the user's question. How the retrieved content is formatted, summarized, and positioned in the prompt determines whether the model uses it accurately or ignores it — making prompt engineering central to the entire system's reliability.
AI Agents (Tool-Using Systems)In AI Agents, a language model is given descriptions of available tools (like web search or a calculator) formatted as part of its prompt. The model decides which tools to call based entirely on how those tool descriptions are written — poor prompt engineering here means agents call the wrong tools or fail to use them at all.
Medical and Legal AI AssistantsOrganizations deploying AI in high-stakes domains use elaborate system prompts that constrain the model's behavior, mandate disclaimers, and specify what the model must refuse. The safety and reliability of these systems is a direct function of prompt engineering quality.
Automated Content PipelinesMarketing and publishing companies use prompt templates with variables (like product names or audience types) filled in at runtime. The template's design determines output consistency across thousands of generations — a poorly designed template produces wildly variable results at scale.
Evaluation and Red-TeamingAI safety researchers use adversarial prompt engineering — intentionally crafting prompts designed to make models behave badly — to discover and patch vulnerabilities before products ship publicly.

Prerequisites

What This Leads To

See Also

Large Language Models · Retrieval-Augmented Generation · AI Agents · In-Context Learning · Chain-of-Thought Reasoning · Fine-Tuning · System Prompts

Before this