Module 1 · Core principles
System role, instructions, examples and data
6 min read
A production prompt is not a sentence: it is an assembly of four ingredients — a role (the model's working context), instructions (what to do, and how), examples (what a good answer looks like) and data (what to work on). This lesson measures what each brings, starting from a hastily written sentence up to a complete prompt, on the same extraction task.
The experiment
The task: from 100 purchase orders (written in varied styles), extract the supplier, the amount before tax, the currency, the due date and whether late-payment penalties apply, as JSON. The local model (Qwen2.5-1.5B-Instruct) receives four versions of the prompt:
def prompt_v0(po: PurchaseOrder) -> list[dict]:
return [{"role": "user", "content": f"extrais les infos de ce bon de commande en json {po.text}"}]
def prompt_v1(po: PurchaseOrder) -> list[dict]:
system = "Tu es un assistant comptable. Tu extrais les informations clés des bons de commande."
user = ("Extrais du bon de commande suivant le fournisseur, le montant hors taxes, la devise, la date "
f"d'échéance et la présence de pénalités de retard. Réponds en JSON.\n\n{po.text}")
return [{"role": "system", "content": system}, {"role": "user", "content": user}]
(V0: "extract the info from this purchase order in json"; V1: an accountant-assistant role and a clear instruction listing the five pieces of information, "answer in JSON".) V2 delimits the document with tags and specifies the output field by field; V3 adds two complete examples. The result is scored by program: valid JSON, then each field against the ground truth.
| Version | Valid JSON | Exact extraction (5 fields) | Supplier | Amount | Currency | Due date | Penalties | Prompt length |
|---|---|---|---|---|---|---|---|---|
| V0 — one sentence | 0.95 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 145 tokens |
| V1 — role + instruction | 0.99 | 0.00 | 0.99 | 0.00 | 0.50 | 0.00 | 0.00 | 181 tokens |
| V2 — tags + format | 0.97 | 0.55 | 0.97 | 0.69 | 0.92 | 0.97 | 0.82 | 323 tokens |
| V3 — V2 + 2 examples | 1.00 | 0.89 | 1.00 | 0.98 | 1.00 | 0.97 | 0.94 | 990 tokens |
What each row says
V0 produces JSON… that is unusable. The model invents its own structure ({"bon_de_commande": {"numero": …}}): 95% valid JSON, 0% usable extractions. Valid JSON is a measurement trap: it says the output can be read, not that it is right.
V1 finds the supplier, and nothing else. A role and a clear instruction are enough to understand the task: 99% of suppliers are found. But the model chooses its own key names (montant_hors_taxes, date_echeance) and formats ("francs suisses", "3 mai 2026", 79200 without indication): no program can consume this output. A role and an instruction do not replace a specification.
V2 makes the main leap: from 0% to 55%. Key names, formats (ISO date, currency code, number without separator) and each field's type are specified. The remaining errors are instructive: the amount is only right 69% of the time — the model sometimes takes the VAT amount instead of the amount before tax, or gets the separators wrong ("23.700 EUR").
V3 shows the right answer: with two complete examples (a document, its JSON answer), exact extraction reaches 89%, at the price of a prompt three times longer. Examples resolve the ambiguities words left open: what "a decimal number" looks like, which amount to take when there are two.
The four ingredients
| Ingredient | Role | Where to put it | Classic mistake |
|---|---|---|---|
| Role | The working context, the audience, the stakes | System prompt | Believing a role ("you are an expert") is enough to obtain expertise |
| Instructions | The task, the constraints, the output format | System prompt (stable) or end of the user message (specific) | Vague instructions ("in JSON"), or contradictory ones |
| Examples | Showing the expected answer, including tricky cases | As user/assistant exchanges, or inside tags | All-similar examples, or different from the real distribution |
| Data | The document to process | Delimited (tags), separate from the instructions | Data pasted into the instruction, with no clear boundary |
The system prompt carries what does not change from one request to the next: the role, the rules, the format. It is also the most "authoritative" channel: models are trained to give it priority over the content of messages, which matters against injections (lesson 4.4). The user message carries what changes: the data, the question.
Explaining the why
An instruction accompanied by its reason is followed better than a bare instruction, especially by large models that generalize from intent. Compare:
- "Answer only in JSON."
- "Answer only with a JSON object: the output is read by a program, any text around it would make it unreadable."
The second says why: the model also understands that it must not wrap the JSON in Markdown code fences, which the first did not forbid. V2's system prompt follows this principle: "so that a program records them: the output must be exact and usable as is".
The price of examples
V3 costs three times more input tokens than V2. At scale, this is not trivial — but two levers reduce it: prompt caching (the examples, identical from one request to the next, can be cached, lesson 3.4) and dynamic selection (sending only the most useful examples for each input, lesson 2.2). And if examples are no longer enough, fine-tuning takes over: precisely the path described in the fine-tuning course.
Key takeaways
- A production prompt assembles a role, instructions, examples and data.
- On the same task: 0% exact extractions with one sentence, 0% with a role and an instruction, 55% with a specified format, 89% with two examples.
- Valid JSON is not a right answer: measure the fields, not just the format.
- The system prompt carries what is stable (role, rules, format); the message carries what changes.
- Explain the why behind instructions; show the expected answer with examples.
Practice
- Run
examples/01_prompt_anatomy.pyand read the outputs of V0 and V1: which keys and formats does the model invent? - Add to V2 a sentence explaining the difference between the amount before tax and the VAT: does the amount score improve?
- Replace V3's two examples with two easy ones (no VAT mentioned): what do you lose?