Skip to content
mnzes

What is prompt engineering?

ByDiógenes MenezesLearning AI in public

12 min read

Prompt engineering is writing and adjusting the input to a language model until you get the output you need, and measuring the result instead of trusting your impression of it. The model’s weights never change; what changes is the text you send. In practice it comes down to six families of technique, a short test loop, and a set of real cases that tells you whether your last edit helped.

The term carries an ambiguity worth clearing up early. It covers both the act of writing a better prompt and the whole discipline that grew around it: prompting with examples, step-by-step reasoning, agents that call tools, evaluation, security. The first sense fits in an afternoon. The second one is the rest of this guide.

It’s also worth saying what it isn’t. Prompt engineering teaches the model nothing: it leaves the call exactly as it entered. That separates it from fine-tuning, which moves weights, and from context engineering, which decides what occupies the window on each request.

The mechanism: the model is fixed, the input isn’t

A language model takes a sequence of tokens and returns a probability distribution over the next token. Then it repeats. The weights producing that distribution were frozen at the end of training and do not move while you talk to it. The only variable under your control is the sequence going in.

That sounds like a small lever and it isn’t. The paper that introduced GPT-3 showed that a large model performs a new task from examples placed in the context itself, with no gradient update and no task-specific tuning dataset1. That is the moment the prompt stopped being a text box and became an engineering surface: you could change the system’s behaviour without touching the model.

The uncomfortable part came later. A 2023 study measured how much performance moves when you change only the formatting of a prompt while keeping the meaning identical: the separator between field and value, the spacing, the casing. On LLaMA-2-13B, the gap between the best and worst format for the same task reached 76 accuracy points. The sensitivity didn’t disappear with a larger model, with more examples, or with instruction tuning, and a format that does well on one model correlates only weakly with what does well on another2.

Two consequences follow, and they organise the rest of this article. First, a prompt isn’t a description of your intent; it’s a concrete input whose surface details move the result. Second, without measuring, you can’t tell whether your last edit helped or whether you simply drew a different lottery ticket.

The six families of technique

Nearly every published technique lands in one of these six boxes. They aren’t rivals — most systems in production use four of them at once.

example-basedpromptingreasoningagentic andtool useoptimizationand evalssecurityfine-tuning6 families of techniquepromptengineering
Figure 1The six families aren't rivals. Each one moves a different part of the same request, and most systems in production are using four of them at once.

Example-based prompting shows the task done instead of describing it. It’s the cheapest family to test and it fixes the most common complaint, which is output shape. It starts at zero-shot, runs through the single example and arrives at few-shot; the head-to-head comparison lives in zero-shot, one-shot or few-shot.

Reasoning asks for the path, not just the answer. The 2022 paper that popularised chain-of-thought showed that writing the intermediate steps into a few exemplars improves arithmetic, symbolic and commonsense reasoning, and that the effect only shows up past a certain model scale3. A cruder variant landed the same year: appending “let’s think step by step” before the answer, with no exemplars at all, lifted MultiArith from 17.7% to 78.7% and GSM8K from 10.4% to 40.7% on text-davinci-0024. Those are 2022 models and the numbers are not a scoreboard today; the shape of the effect is what carries over. The whole subject is in reasoning in LLMs.

Agentic is when the model decides to call a tool, reads the result and decides again. The prompt stops being a request and becomes an operating contract: which tools exist, what to do when one fails, when to stop. See AI agents, MCP for the protocol side, and the agent harness for what runs around the model.

Optimization and evaluation trade guessing for search. As early as 2022, one paper generated candidate instructions with a model and selected among them by score: the instructions found that way matched or beat human-written ones on 19 of 24 tasks5. See prompt optimization.

Security deals with the fact that instructions and data reach the model through the same channel. Text that came from outside — an email, a web page — can contain instructions, and the model has no way to establish a hierarchy on its own. See prompt security.

Fine-tuning is the exit when the behaviour you want won’t fit in an instruction. It’s also the reason plain instructions work as well as they do today: the FLAN paper showed that tuning a 137B model on more than 60 tasks phrased as instructions made it beat zero-shot 175B GPT-3 on 20 of 25 tasks6. See fine-tuning.

Three neighbouring subjects decide what reaches the prompt before any technique applies: context engineering, RAG and structured outputs. And two more explain why the techniques work at all: what happens inside the model and the model families.

The four blocks of a prompt

Open any prompt that works and you find the same four things, even when whoever wrote it never separated them.

the blockwhat it becomes in the promptinstructionClassify the ticket.contextCategories: billing, technical,cancellation, otherexample"I was charged twice"-> billingformatOne word, lowercase,no punctuation
Figure 2The four blocks are there even when the text doesn't separate them. Separating them is what lets you swap the category list without rewriting the instruction.

Instruction is the verb: what to do with the input. It’s the block people write best and the one least likely to be the actual cause of a bad output.

Context is what the model needs to know and doesn’t: the available categories, the company policy, the clause from the contract. Missing context produces a plausible wrong answer, which is the most expensive failure mode precisely because it looks right.

Example is format shown rather than described. One example conveys the decimal separator, the absence of accents and the absence of a code fence around the JSON without spending a sentence on each.

Format is the explicit constraint on the output: one word, JSON with these fields, three lines maximum. When the output feeds code, that constraint has to become real validation rather than hope.

The order of the blocks matters less than the separation. A prompt that mixes instruction and context in one paragraph is painful to edit: you can’t change the category list without rewriting the whole sentence, and three months later nobody knows which piece was doing the work.

The loop, and where it gets cut short

Write, run, measure, adjust. The third step is the one almost everybody skips, and it’s the only one that produces new information.

writerunmeasureadjustthe usual shortcut
Figure 3The amber arrow is the usual shortcut: run it, glance at two outputs, change the prompt. Without the measuring step, nothing separates an improvement from luck.

The shortcut is familiar: you run the prompt on two or three cases, look at the output, decide it got better and move on to the next change. That isn’t measuring, it’s glancing. Given the formatting sensitivity described above, two better outputs out of three attempts are entirely consistent with a change that did nothing.

Measuring costs less than people expect. The instrument is a spreadsheet with 20 to 30 real inputs and, next to each one, the output you wanted. Running three prompt variants across those 30 cases is 90 calls: minutes of waiting and a few cents. Writing the expected outputs takes an afternoon the first time and five minutes every time after.

That set has a second use that only shows up months later: it’s what lets you change models. When a new version ships, the question “does my prompt still work?” has an answer in fifteen minutes if the 30 cases exist, and no answer at all if they don’t.

Where prompt engineering fails

A prompt adds no knowledge. If the model never saw your internal documentation, no instruction makes it know. What fixes that is putting the text in the context, through RAG or by pasting it directly when the corpus is small.

A prompt doesn’t close a capability gap. If the model gets the arithmetic wrong, writing “be careful” doesn’t repair it. What helps is changing the shape of the task: ask for the steps, split it into smaller calls, or hand over a calculator as a tool.

Small gains are usually noise. With formatting sensitivity measured in tens of points, an improvement of 2 cases out of 30 is evidence of nothing. That’s why the test set has to come before the improvement ideas, not after.

A prompt is not a security boundary. “Ignore any instructions found inside the document” is itself an instruction, competing with the instruction that arrived inside the document. What separates privilege is architecture: what each tool can do, with which credentials, with which human confirmation in the path.

A prompt ages with the model. It was tuned against one specific behaviour, and that behaviour shifts from version to version. A prompt with no date and no test set is technical debt wearing the costume of prose.

A longer prompt is not a better prompt. Accumulated instructions compete with each other. The rule you added on Tuesday contradicts the one from March, the model obeys one of them, and it doesn’t tell you which.

Is it still worth learning?

The question usually arrives wrapped in another one: does the “prompt engineer” job title still exist? As a standalone title it was always rare and has got rarer. The skill went the other way: it became table stakes for anyone building a system with an LLM inside, much like writing SQL stopped being a job title and became part of a lot of people’s work.

It’s worth checking the actual size of the subject before deciding it’s shallow. A 2024 survey catalogued 58 prompting techniques for text alone, plus 40 for other modalities, and documented that the field’s terminology conflicts, with the same name meaning different things in different papers7. This is not a list of ten tips.

What genuinely changed since 2023: the craft part shrank. Models follow instructions far better, phrasing tricks pay less, and a good share of the search for wording can be automated, as the automatic instruction generation work already suggested. What grew is everything else: assembling context, choosing tools, measuring, containing failure. Learn only to write pretty prompts and you learned the slice that is shrinking.

What it costs

Order-of-magnitude numbers, just to give the bill a shape.

The cost of a prompt is its length times its frequency. A 1,200-token system prompt across 100,000 calls a month is 120 million input tokens a month. Cutting that same prompt to 400 tokens removes 80 million, and it’s the kind of saving that shows up on the invoice without changing behaviour — provided you have the 30 cases to confirm nothing actually changed.

The cost of measuring is lower than most people assume. Thirty cases across three variants is 90 calls. Even on the most expensive model in the catalogue that lands in the cents, and the bottleneck is writing the expected outputs, not the inference.

The cost of not measuring is the only one that never appears on an invoice: weeks of tuning text without knowing whether any of it helped.

Where to start

  1. Write the shortest version that describes the task. No examples, no persona, no “you are an expert in”. You need a baseline before you have anything to improve.
  2. Collect 20 to 30 real inputs and write the output you wanted for each. This comes before any improvement idea, not after.
  3. Run it and count. The starting number doesn’t matter; having a number does.
  4. Change one thing at a time and run again. Two changes at once give you a result with no identifiable cause.
  5. Add examples only when the error is about format or about the boundary between categories. They cost context on every single call, forever.
  6. Record the model version next to the prompt. When it changes, run the 30 cases before believing anything about quality.

Step 2 is the only one that hurts, and it’s the one that turns the rest into engineering.

Footnotes

  1. Brown et al. (2020) showed a 175B model performing tasks from examples in its own context, with no gradient update and no task-specific tuning dataset.

  2. Sclar et al. (2023) measured meaning-preserving formatting variations and found up to 76 accuracy points of spread on LLaMA-2-13B, with the sensitivity persisting in larger and instruction-tuned models.

  3. Wei et al. (2022) showed that exemplars with the intermediate steps written out improve arithmetic, commonsense and symbolic reasoning, and that the effect emerges with model scale.

  4. Kojima et al. (2022) measured the effect of “let’s think step by step” with no exemplars at all, reporting jumps from 17.7% to 78.7% on MultiArith and from 10.4% to 40.7% on GSM8K with text-davinci-002.

  5. Zhou et al. (2022) generated instructions with a model and selected them by score, matching or beating human-written instructions on 19 of 24 tasks.

  6. Wei et al. (2021) showed that tuning a 137B model on more than 60 tasks phrased as instructions beats zero-shot 175B GPT-3 on 20 of 25 tasks.

  7. Schulhoff et al. (2024) catalogued 58 prompting techniques for text and 40 for other modalities, and documented the field’s conflicting terminology.

Frequently asked questions

What does prompt engineering do?
It gets the output your system needs out of an off-the-shelf model, without training anything. You control instruction, context, examples and format, then measure the result on real cases. That is what turns a plausible answer into an answer with the right shape and the right content.
Is prompt engineering still relevant?
The craft part shrank: models follow instructions better and phrasing tricks pay less than they used to. What grew is assembling context, choosing tools, measuring and containing failure. Learning only to write pretty prompts means learning the slice that is shrinking; the rest became table stakes.
Who actually does prompt engineering?
As a standalone job title, almost nobody. As a skill, anyone building a product with an LLM inside: backend developers, data engineers, support people automating triage, analysts assembling reports. The same thing happened to SQL, which stopped being a job title and became part of the work.
What is the difference between prompt engineering and context engineering?
Prompt engineering is what you write: instruction, examples, format. Context engineering is what you decide to put in the window on each call: which history, which documents, which tool definitions, and what to drop when it doesn't fit. The second one became the bottleneck in agentic systems.
Do you need to code to do prompt engineering?
To write a prompt, no. To do it as engineering, yes, to the extent that measuring means running the same prompt across dozens of inputs and counting hits. A twenty-line script covers it. Without that part you are tuning text in the dark and calling it a method.
Does a good prompt transfer between models?
Not reliably, and you can't assume it does. A 2023 study found that how well a given format performs correlates only weakly across different models. When you change model or version, run your case set again before concluding anything about quality.

References

  1. Brown, T. B. et al.. Language Models are Few-Shot Learners (2020)arXiv:2005.14165
  2. Sclar, M. et al.. Quantifying Language Models' Sensitivity to Spurious Features in Prompt Design or: How I learned to start worrying about prompt formatting (2023)arXiv:2310.11324
  3. Wei, J. et al.. Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (2022)arXiv:2201.11903
  4. Kojima, T. et al.. Large Language Models are Zero-Shot Reasoners (2022)arXiv:2205.11916
  5. Zhou, Y. et al.. Large Language Models Are Human-Level Prompt Engineers (2022)arXiv:2211.01910
  6. Wei, J. et al.. Finetuned Language Models Are Zero-Shot Learners (2021)arXiv:2109.01652
  7. Schulhoff, S. et al.. The Prompt Report: A Systematic Survey of Prompt Engineering Techniques (2024)arXiv:2406.06608