LLM Fundamentalsgpt-oss-120b on Groq · groq 1.7 · Python 3.10+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
19 small wins to finish your pathNext lesson →

Few-shot prompting

Few-shot prompting is a way of teaching a task inside the prompt by adding a few solved examples as earlier user and assistant turns.

Last updated: 30 Sep, 2026 · groq 1.7 · gpt-oss-120b on Groq

Describing a task only goes so far. Showing solved examples often works better. This lesson continues the file from System prompts: ask, tickets and structured come from there.

Three solved examples

python
examples = [
    {"role": "user", "content": "You took money from my card two times"},
    {"role": "assistant", "content": '{"category": "billing", "priority": 4}'},
    {"role": "user", "content": "Where is my delivery? It is a week late"},
    {"role": "assistant", "content": '{"category": "shipping", "priority": 3}'},
    {"role": "user", "content": "Can I change the email on my account?"},
    {"role": "assistant", "content": '{"category": "other", "priority": 2}'},
]

Three made-up tickets, one per category, each followed by the answer you want. They go between the system prompt and the real ticket, so the model reads them as a conversation it has already had. None of them is one of the seven test tickets.

Syntax: [system, *examples, user]. *examples spreads the list's items into the new list.

Sorting with the examples in front

ExampleAPI key
for text, expected in tickets:
    messages = [{"role": "system", "content": structured}, *examples, {"role": "user", "content": text}]
    print(f"{expected:9} {ask(messages)}")
  • The same five tickets are right, in the same JSON shape.
  • The fee and the cancellation are still shipping. The examples show a double charge, a late delivery and an account change. None is about a fee or a cancellation, so they gave the model nothing to go on for those two.
  • Two priorities changed from the structured-prompt run, and the categories did not.

Why examples change the answer

In Next-token prediction, every token in front of the answer changes the next token's scores. Solved examples put answers in front of the model: after a double charge came billing, so billing becomes likelier after the next charge. The model is not trained by them; its weights do not change. It continues a pattern it can see.

Instructions vs examples

Instructions (system prompt)Examples (few-shot)
TeachesThe rules, in wordsThe pattern, by showing it
Covers edge casesOnly the ones you write downOnly the ones you show
TokensSent with every requestSent with every request, usually more

When examples help most

  • When the output format is fiddly and easier to show than to describe.
  • When the model keeps making the same mistake: an example of exactly that case.
  • With smaller models, which follow patterns better than long instructions.
Watch out. Never copy test tickets into the examples. The score would then measure copying, not how the prompt handles new tickets.
Try it yourself
  • Write a fourth example of your own about cancelling an order, with other, and run it again.
  • Put the three examples in a different order.
  • Remove the system message and keep only the examples.

You understood something today that you didn't yesterday.