Working with AI

Advanced prompting techniques

Advanced prompting is a five rung ladder: zero shot, few shot, chain of thought, structured output and system prompts. A higher rung is not better, it is more; and on today reasoning models the vendors own guidance says the third rung is usually one you should not climb.

  • Lesson 4 of 15
  • Intermediate
  • Free, no signup

Five rungs, bottom to top

Each rung adds something to the prompt. None replaces the rung below it, and none on its own is a sign of expertise.

  1. 1

    Zero shot

    You simply ask. Four out of five real tasks finish right here.

  2. 2

    Few shot

    Two to five correct examples. For when the shape of the work is easier to see than to describe.

  3. 3

    Chain of thought

    The steps before the answer. Today it is more for seeing the reasoning than for improving it.

  4. 4

    Structured output

    A fixed shape a program can read. The only rung that makes quality measurable.

  5. 5

    System prompt

    The standing rules, written once. It is a rule usually followed, not a wall.

The third rung is usually unnecessary on today reasoning models, and the vendors own guidance says so. The page text gives the source for both.

Last checked: Facts and tool names in this lesson are re-checked against their sources on this date.

What the five rungs are, and what a higher rung means

All five techniques in this lesson do one thing: they add something to the prompt that was not there. Zero shot means you simply ask. Few shot means you also include a handful of correct input and output pairs. Chain of thought means you ask for the steps before the answer. Structured output means you fix the shape of the answer so that a program can read it. A system prompt means rules that apply to every message and are not repeated each time.

Here is the point most tutorials lose: this ladder is not a quality scale. A higher rung does not give a better answer, it makes a bigger prompt. Every rung you climb adds three things: tokens, latency, and one more thing that can be wrong. An example that contradicts your own rules is worse than no example.

So the working rule is this: start on the first rung and climb only when an output has shown you where it fell short. Four out of five prompts in real work stay on rung one, and that is not a sign of a beginner.

A glass ladder of five rungs lit from red at the bottom to white at the top, none brighter than the rest

Giving examples: how many is enough, and when it backfires

The term few shot comes from the 2020 OpenAI paper titled "Language Models are Few-Shot Learners", and the idea is simple: instead of describing the task, show a handful of examples of it. For work whose shape is easier to see than to describe, this rung genuinely pays: classification, tone, and any format with fussy details.

A real example. Say you want to sort incoming customer messages into four buckets. Zero shot, the prompt says "put this message in one of these four buckets" and the model gets most of them right and improvises on the borderline ones. Few shot, you choose those borderline ones yourself:

Message: Hi, order 123 arrived yesterday but the box was dented. The item inside is fine.
Bucket: complaint

Message: Could you tell me when order 123 arrives?
Bucket: order status

Message: Hello. I want three more of the last one.
Bucket: new order

The value of those three lines is in the thing you could not write down: that "dented box, item fine" still counts as a complaint is your decision, not a general rule. Examples carry exactly those borderline decisions.

On how many, there is no magic number and anyone who gives you one is guessing. OpenAI own guidance for reasoning models says to try zero shot first and add examples only if needed, and warns on the same page that examples must align closely with the instructions, because a discrepancy between the two produces poor results.

Three places where examples backfire: when they all come from one bucket and the model copies that distribution; when one example contradicts one of your own rules, in which case the model believes the example rather than the rule; and when the examples are lifted from real client data, because that data now travels with every single run.

Where chain of thought came from, and why it is needed less now

January 2022, a paper from Google researchers appeared under the title "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models". Its claim was that if your examples also show the intermediate steps to the answer, sufficiently large models do better on arithmetic and logic problems. That paper is where "think step by step" entered every tutorial.

Nearly five years later, the vendors own guidance says something else. The OpenAI page on getting the best out of reasoning models says to keep prompts simple and direct and to avoid chain of thought prompts, because these models reason internally and telling them to think step by step is unnecessary. Anthropic documentation on extended thinking says to prefer general instructions over prescriptive steps: a prompt like "think thoroughly" often produces better reasoning than a hand written step by step plan.

So the technique did not become wrong; it moved. It went inside the model. Two places still want it: smaller and older models with no internal reasoning, and any time you want to see the steps so you can argue with them. The second is a good reason, and the reason is inspection rather than answer quality.

One warning you will rarely read: the steps a model prints are not a report of what happened inside it. That text was generated the same way the rest of the text was. An answer can be right with irrelevant steps, or the steps can be convincing and the answer wrong. Treat it as an explanation offered to you, not a stamped receipt. That is our position, and it follows from the mechanism described in the lesson on large language models.

Take the date at the top of this page seriously. Vendor guidance is exactly the kind of thing that turns over fast here, and this passage is exactly the kind of claim that may be half wrong a year from now.

Chain of thought: where it still pays and where it is just tokens

One technique with two entirely different uses. One of them is fading and the other is not.

To improve the answer

  • Usually unnecessary on today reasoning models
  • Two vendors guidance says keep the prompt simple
  • Still helps on smaller and older models
  • Adds tokens and latency, and sometimes makes the result worse

To see the reasoning

  • When you need to see where an answer came from
  • For finding exactly where a multi step task went wrong
  • When you have to explain the answer to somebody else
  • This use does not fade as models improve

Even in the second column, the printed steps are not a report of what happened inside the model. They are an explanation offered to you.

Structured output: when the answer has to enter a program

This is the one rung that nearly always pays for itself in real work, and the reason is not text quality: an answer with a fixed shape can be checked by machine. As long as the output is a fluent paragraph, the only way to evaluate it is to read it. When the output is a record with named keys, five lines of code tell you which record is broken.

There are two ways to get it and the difference matters. The first is to ask for the shape in the prompt and hope. The second is to use the mode the vendors built for this, which constrains the output to a schema; Anthropic and Google both keep separate documentation for it. If you work through an API, take the second. If you work in a chat window, the first is your only option and then checking the output is your only guarantee.

A trap specific to Persian and Arabic writers that you will not find in any English documentation: if your rules say "a number between 1 and 3" using Persian or Arabic-Indic digits, the model may well answer with those digits, and the output stops being valid JSON, because JSON accepts Latin digits only. The fix is one sentence: say in the rule that digits must be Latin. We put that into the recipe below.

And a habit worth more than the technique: never let a structured output directly perform something that is hard to undo. Sending an email to a customer, filing a return, changing a price. Put a person between the output and the action, at least until you have run it over a hundred real records.

System prompts: rules you do not repeat every time

The system prompt is where the standing rules of your work sit, applying to every message in that conversation. In an API it is a separate parameter and Anthropic keeps a dedicated documentation page for it. In chat products it is the thing you meet under names like custom instructions or project instructions.

What belongs there: who you are and who you write for, the constraints that never change, and output conventions such as never wanting a bulleted list. What does not belong there: the details of one specific task, anything that changes per request, and obviously no passwords or keys.

A point missing from most tutorials: a system prompt is not a security boundary. It is a rule the model usually follows, not a wall nothing crosses. Text you paste in your next message, the contents of a web page or a customer message, can carry an instruction inside it that contradicts your rules. That is the thing named properly in the block further down this page.

Where not to put these techniques

Four situations where climbing the ladder is only a cost. First, a one off: something you do once is not worth examples, a schema and a system prompt; ask, read the answer, done. Second, when the problem is missing information: if the right answer needs data the model does not have, no rung conjures it and the fix is supplying the data.

Third, when the output is for a person rather than a program. Structured output there only adds friction and makes the text stiffer. Fourth and biggest: when you have no way to check the result. More technique makes a wrong answer look more confident and more orderly, which makes it more dangerous. If you cannot say what a correct output looks like, solve that first.

One summary worth repeating: of these five rungs, the one with the highest return in day to day work is structured output, because it is the only rung that makes quality measurable. The others change the quality and leave the measuring where it was.

Where to add a technique and where to stop

The second column matters more. Most over engineered prompts exist because nobody read it.

The prompt decision sheetbefore you climb the ladder

Add a technique

  • The same task will run dozens of times
  • You have borderline decisions that are hard to write down
  • The output has to enter a program or a spreadsheet
  • You carry standing rules you retype every time

Stop here

  • It is a one off
  • The problem is missing information, not prompt shape
  • A person reads the output, not a program
  • You have no way to check whether the result is right

None of these is a hard law. If your case fits in both columns, take the simpler one.

The fast path, with AI

The fastest professional form of these five rungs is the fourth one combined with something almost no tutorial says: the model does not have to be right the first time. You ask for the shape, you read the output with a mechanical check, and you hand the error list straight back so it rebuilds only the broken records. Against fixing by hand, the difference is invisible at ten records and it is an afternoon against a week at two hundred.

  1. Write the output shape once, filled in, instead of describing it. One sample record with every key, including the keys that are empty in that sample.
  2. Ask for that same shape across all your inputs and say plainly that nothing else should be written. This round is mechanical work and a fast cheap model is usually enough.
  3. Read the output with a mechanical check, even if that check is only a json.loads. What you cannot check by machine is not structured in practice.
  4. Hand back the error list with the record identifiers and ask only for those records again. One repair round is usually enough; if the second round still errors, the fault is in the shape you asked for rather than in the model.
  5. The last step is yours. A mechanical check confirms shape, never truth; read a random sample of the records yourself.

Copy-ready recipe

Part one, extraction:

Build this same record from each text below and write nothing else.

The record shape, exactly these keys in this order:
{"id": "m-001", "bucket": "complaint|order_status|new_order|other", "urgency": 2, "summary": "one sentence, fifteen words maximum", "phone": null}

Rules:
- "urgency" is a number between 1 and 3, in Latin digits. Do not use any other digit forms, because JSON does not accept them.
- 3 means the customer is waiting for an answer today.
- If there is no phone number in the text, leave "phone" as null and do not invent one.
- If a text fits none of the four buckets, use "other" and say why in "summary".

Output: a JSON array only. No commentary, no code fence, no text before or after it.

Texts:
{one text per line, with its identifier at the start}


Part two, repair (after the check has run):

This was your output and these are the errors the checker found:
{error list, each with the record identifier and the reason}

Return only those broken records again, in the same shape and under the same rules. Do not resend the records that passed and do not write anything else.

Before you trust the output: A mechanical check confirms shape, not truth. A record can be perfectly formed and completely wrong, and that urgency number in particular is a judgment the model has no way of knowing. Before this output is wired to anything, read a random sample yourself, and never let a record directly perform something that is hard to undo.

AI in this kind of work

The question that actually matters here is this: which model holds one fixed shape across twenty records in a row? That is not the same as which model is smarter, and no leaderboard we use measures it. Our own ranking criteria are the same story: arena score, score per dollar, context window, tool maturity and access from Iran. Not one of them is instruction adherence. So the honest answer is that you measure this yourself in an hour: twenty real inputs, one fixed schema, and a count of the records that came back out of shape. The number that falls out of that is worth more for your work than any ranking.

Tools that actually help

  • Claude It keeps separate documentation for the fourth rung and constrains the output to a declared schema, which is a different thing from asking for a shape inside the prompt. Iran is on neither of Anthropic two supported-countries lists; we read that on Anthropic own page.
  • Gemini It also documents a structured output mode, and its prompting guide is the most explicit of the three. Google own page says the Gemini web app runs in over 230 countries and territories, and Iran is not on that list.
  • ChatGPT The most common choice, and its reasoning model guide is where two of this lesson claims about chain of thought and examples come from. We make no claim about access from Iran: the main OpenAI domain returns an access error to this server.

Where it backfires

The specific risk in these techniques has a name: prompt injection. The moment your prompt takes in text you did not write, the contents of a web page, a document, or the customer message the recipe above works on, an instruction sitting inside that text can change how the model behaves. The OWASP foundation lists this first among its ten risks for applications built on language models and states plainly that such an instruction does not need to be readable by a human; it only needs the model to parse it. The fix is not a magic sentence in the system prompt, because that is a rule and not a wall. The practical fix is three things: never wire model output straight to something hard to undo, keep every key and password out of the prompt, and read unknown text on the assumption that it may contain an instruction. The second risk is quieter: a record can be flawless in shape and entirely invented in content, and structure makes wrongness look tidy and convincing.

Sources: OWASP: LLM01 prompt injection Anthropic: structured outputs Anthropic: system prompts Google: structured output with Gemini

Where this advice stops

What this page says has a shorter shelf life than usual and it is better not to hide that: the chain of thought passage stands on two vendors guidance, and vendor guidance is exactly what turns over fast. Nor have we benchmarked any of these five techniques on this server; what we have is the papers and the vendors own documentation, and all of it is linked. Third, this whole lesson is about text models, through a chat window or an API; none of these rungs means anything for image models. Last, this page does not say which model is the most obedient, because our own ranking does not measure that; what we do measure, with sources, sits in the chatbot ranking and, for code work, the coding model ranking.

From our own work

The learning section you are reading is itself an instance of the fourth rung. Every lesson is a data file with a fixed shape, and a validator runs over it before the page is ever built; that validator carries 23 rejection rules, from a missing limit block to a dead internal link to a chart showing a number with no source. Why so strict: in the AI section of this site a multilingual field was once written as a plain string instead of a four language array, and the result was Persian text printed on English pages. No instruction in any prompt prevented that; what prevented it was a three line condition that rejects a plain string. The practical lesson for your own work is the one in the recipe above: ask for the shape, then check the shape.

Real follow-up questions

How many examples are enough for few shot?

There is no fixed number, and any number you read somewhere was a guess. OpenAI guidance says to try zero shot first and add examples only if needed. The practical method: start with two, add one at a time, and watch your test inputs to see whether the output changed. Where another example stops changing anything, that is your answer.

What is the difference between a system prompt and the same sentence at the top of a message?

Persistence. A sentence you type into a message belongs to that message; a system prompt applies to every message in the conversation and you do not retype it. In chat products the same thing goes by custom instructions or project instructions. Neither of them is a security boundary, though, and text you paste later can ask for the opposite.

Should I still write "think step by step"?

If the model reasons internally, the vendors own guidance says no and tells you to keep the prompt simple. If you are on a smaller or older model, it can still help. There is one exception that has nothing to do with quality: when you want to see the steps so you can work out where an answer came from, asking for them is still right.