Skip to content

Prompt engineering

Prompt engineering is writing, testing and revising the instructions for a language model until it does a task reliably, measured against cases with known answers.

Select any words here to ask your Maestro about them.

You wrote a prompt that pulls the total out of an invoice, and it worked perfectly on the first one you tried. You run it on 50 invoices whose totals you already know. Where do the misses land?

A prompt that pulls the total out of each invoice, tested on 50 invoices with known totals. Example data.

What it is: writing and revising the instructions you give an LLM so it does a task well, reliably: state the task, give context, set rules and examples, and ask for an output format. A prompt that worked once isn't a tested prompt.

How to do it well: collect cases with known answers, run the prompt on all of them, read the misses and change one thing at a time. Score every version on the same cases, and keep a few back you never tune on.

Beyond the prompt: in an AI agent, what matters most is often not the wording but what information reaches the model: that's context engineering. Even with a good prompt, check for hallucinations.

Practice this in the free course Check What AI Gives You.

How it's used

The parts of a prompt

Prompt: an invoice's total

  1. marked: The task: "Pull the amount due out of this invoice."What you want, in one sentence.
  2. The context: "These are supplier invoices, as PDFs or scans."What the model can't guess.
  3. The rules: "The total is the last amount labeled Total, after tax."Each rule comes from a mistake you saw.
  4. An example: one hard invoice and its right answerOne example teaches more than a paragraph of rules.
  5. The format: {"total": number or null, "currency": the code printed on the invoice}A fixed output can be checked with code.
The part that improves a prompt most isn't in it: the set of cases with known answers you test it against.

When to look closer

Tuning on the invoices you score with

Prompt 4

  1. marked: On the 50 invoices you tuned it on: 49 right

Your prompt gets 49 of the 50 invoices you kept fixing it on. How many of November's will it get right?

Ask your Maestro about Prompt engineering

It answers from the free course page closest to this word, the way it answers while you study.

Example

You: What does "Prompt engineering" mean, in plain words?

Your Maestro: I'll explain it with a case of yours: it sticks better than a definition. Which task do you keep giving AI that you'd like it to get right every time?

Asking about: Answers from the page "You already do data engineering"

Only this browser keeps what you ask here. How it works

Learn more

  • Prompt

    A prompt is what you write to an AI model to ask it for something: the question or instruction, plus everything you give it to work with, like data, examples or the format you want back.

  • LLM (large language model)

    An LLM is a program trained on huge amounts of text to continue a piece of text one chunk at a time: it works out which chunk is likeliest to come next and writes it. ChatGPT, Claude and Gemini all run on an LLM.

  • Context engineering

    Context engineering is choosing what goes into an AI model's context window at each step (instructions, files, tool results, history) so it has what it needs and little else.

  • AI hallucination

    A hallucination is an answer from an AI model that sounds confident and well written but is false or comes from no source at all: a number, a fact or a quote nobody ever said.

The whole glossary