Few-shot and in-context learning.

Show a model the task right inside the prompt. A short instruction, or a few worked examples, and it follows the pattern. Nothing about the model changed. No retraining happened.

In-context learning is how a large language model picks up a new task from material placed in its prompt, with no change to its weights. We walk it the way the field is built: what it is, why it surprised people, how it works, what it unlocks, and where it is heading. The papers behind each idea are linked, so you can read the source yourself.

Learning a task from the prompt, not from a training run.

The field name is in-context learning. Few-shot is the everyday name for the version where you show a small handful of examples.

Most software learns a task the slow way. You collect thousands of labeled examples, retrain the system, and ship a new version. Change the task, and you do it all again. A large language model can skip that loop for many tasks. You show it the task inside the prompt: a short instruction, or a few worked examples of input and the answer you want, then the real input. The model reads those examples and produces an answer that follows the pattern.

The clean teaching device, from the GPT-3 paper (Brown et al., 2020), is a ladder. Zero-shot is just an instruction, no examples. One-shot is one worked example. Few-shot is a small handful. The model is byte-for-byte the same before and after. The only thing that changes is how many examples you show it.

A relatable version: think of briefing a new colleague before a call. You do not send them back to school. You hand them three past deals written up the way your team writes them, say "do the next one like these," and they match the format and tone. The examples do the teaching. The colleague is the same person before and after.

Teach the pattern inside the prompt
Examples included in this prompt

“Send the quote.”

Request

“What does it cost?”

Question
New message“Please share the revised pricing.”
Follow the demonstrated patternRequest
Same model weights. Different context.
A few worked examples show the model the task and output pattern. In-context learning happens through the prompt, without a training update to the model’s weights.
Change the examples, without updating weights

Training

  1. Labeled dataset

    Build a set of training examples.

  2. Optimize weights

    Produce an updated model.

In-context learning

  1. Prompt examples

    Put demonstrations beside the new input.

  2. Generate

    Use the existing model weights.

Both can change observed behavior. Only the training path here updates model parameters.

The contrast with the older default.

Supervised learning updates a model's weights through training. In-context learning does the adapting at inference time, inside one prompt.

Why this matters in one line: one general model can take on many tasks, and switch between them, by being shown what to do rather than being retrained for each. The survey by Dong et al. (2023) gives the formal definition and a map of the vocabulary if you want the full scope.

That same mechanism is what lets one model adapt to how a particular company sells, without a custom training run for each one. The way a team labels a stage, the fields they care about, the phrasing in a call summary: all of that can be shown to the model as examples in the prompt, so the same model behaves one way for one team and another way for another. We offer this as an example of the idea, not as a description of any product's plumbing.

It was not supposed to work this well.

A model trained only to predict the next word was not explicitly taught to learn from examples in its prompt. That this ability appears at scale is the surprising result, and it comes with real caveats.

The surprise

An ability nobody trained in directly.

Next-word prediction was the only stated objective. Learning a fresh task from a few prompt examples emerged as a side effect at scale. The GPT-3 paper is where this was named and measured.

Sensitivity

Wording and order move the answer.

The same task can get very different results depending on which examples you pick, what order they are in, and how the prompt is phrased. This is a real, measured fragility, not a rumor.

What examples teach

Mostly the shape, not the exact label.

A landmark study found that randomly corrupting the labels in the demonstrations barely hurt performance on many classification tasks. The examples were mostly teaching format and the space of valid answers.

No memory by default

Adaptation is per-call.

In-context learning lives inside a single prompt. Unless the surrounding system deliberately carries information forward, the model does not retain what it picked up from one prompt to the next.

Finite room

Context is a budget.

Examples cost space in the prompt. There is a ceiling on how many you can include, which forces choices about which examples earn their place.

Prompt as boundary

The prompt is where task and data meet.

Whatever goes into the prompt is what the model sees. In an enterprise setting that makes the prompt a boundary worth respecting: examples and context should be drawn only from material the asker is permitted to see.

Read the pattern, continue the pattern.

At core, the model is still doing next-token prediction. The prompt sets up a pattern, and the model continues it. No gradients, no fine-tuning, no saved change to the model.

1What a demonstration contributes

Examples set the shape of the answer.

Demonstrations appear to specify the format of an answer, the label space or range of valid outputs, and the rough kind of input, more than they teach an exact input-to-label mapping. The clean illustration is Min et al. (2022): shuffle the labels in the examples and much of the benefit survives.

The practical upshot is that the shape and relevance of the examples matter a great deal. Choosing examples that look like the real input, and laying them out consistently, is doing most of the work.

Examples specify the task’s output shape
Input: Renewing the 40-seat plan.
Output: Renewal

Input: Adding a second department.
Output: Expansion

Allowed labels: Renewal, Expansion, New logo
Demonstrations convey the input format, label set, and task. Example quality and label correctness still matter in practice.

2One theory of the mechanism

Inferring the task the examples have in common.

One influential account frames in-context learning as the model inferring a hidden concept, or task, that ties the examples together, then applying it to the new input. Under this view the examples are evidence the model uses to locate which task it is being asked to do. The reference is Xie et al. (2022), which frames it as implicit Bayesian inference.

We present this as a prominent explanation, not settled fact. The field is still actively working out the full mechanism, and the Stanford AI Lab explainer is candid that part of it remains, in their word, mysterious. Honesty here is the point.

Infer the common pattern across examples
InputDemonstrated output
Call ARenewal · $40k · Q3
Call BNew logo · $12k · pilot first
Implied task

Produce a short deal summary using the same fields for Call C.

One account of in-context learning is that examples provide evidence about the task to apply.

3Chain-of-thought

Examples that show the reasoning, not just the answer.

For multi-step problems, including the intermediate reasoning steps in the few-shot examples, not only the final answer, substantially improves results on arithmetic, commonsense, and symbolic tasks. The model imitates the worked-out reasoning, not just the format of the answer. The reference is Wei et al. (2022).

This is in-context learning applied to how to think, not only what to output. A related practical thread, which we keep light here, is that many of these behaviors strengthen as models grow. Few-shot ability in particular was reported to improve with scale. There is live debate about how sudden such jumps really are versus how they are measured, so we state the trend and avoid hype.

Show the method as well as the answer

Answer only

3 reps, 4 calls each.
Answer: 12.

Worked example

3 reps × 4 calls = 12.
Answer: 12.
A worked demonstration exposes intermediate steps that the model can imitate on a new problem.

4Engineering around the fragility

Choosing and arranging the examples is real work.

Because results depend on example choice, ordering, and wording, real systems put effort into selecting and arranging the examples and the instruction. We describe this as a general practice in the field, and make no claim about any particular pipeline.

This is also where in-context learning meets retrieval. The same prompt slot that holds few-shot examples can hold evidence pulled in for the question at hand. Both arrive the same way, as material placed in the prompt for the model to use. We cover that mechanism on the retrieval-augmented generation page.

Treat the example set as a design choice
  1. Select

    Choose examples relevant to the expected inputs.

  2. Cover

    Include important classes and difficult cases.

  3. Order

    Test whether ordering changes results.

  4. Evaluate

    Check the prompt on inputs not used as demonstrations.

Example selection and prompt wording affect behavior. Evaluate the complete prompt, rather than assuming any few examples will work.

What in-context learning unlocks.

At the field level, and with the enterprise touches offered as examples of the idea, never as product claims.

One model, many tasks

No retraining per task.

Summarize, classify, extract, rewrite, draft: all reachable by changing the prompt rather than shipping a new model. The task switches; the weights do not.

Adapting to a team

Behave the way one team expects.

A team's stage names, the fields they track, the tone of their notes, the way they phrase a recap: all can be shown as examples so one model fits that team without a bespoke training run. An example of the idea, not a product claim.

Fast iteration

Edit examples, not datasets.

Changing behavior means editing examples and instructions, which is far faster than collecting a dataset and retraining. The feedback loop shrinks from weeks to minutes.

Reasoning on demand

Harder questions become tractable.

Multi-step problems open up by showing worked reasoning in the prompt, without a specialized model for each kind of question.

A fit with retrieval

It consumes what retrieval pulls in.

Few-shot examples and retrieved evidence both arrive as material placed in the prompt. In-context learning is the mechanism that puts that material to use. More on the RAG page.

Isolation by construction

One team's examples don't shape another's answers.

Because adaptation happens per prompt rather than in shared weights, what one team shows the model does not bleed into another's answers. A property of the mechanism, offered as an example, not a product claim.

The prompt carries both the task and the data.

Because examples and inputs meet inside the prompt, what enters the prompt is exactly what the model can use.

In an enterprise setting that makes the prompt a boundary worth respecting. The principle is simple: examples and context should be drawn only from material the asker is permitted to see, because the prompt is where the task and the data come together. We describe the principle here; the specific mechanism for constructing a prompt under access control is out of scope for this page.

This connects to two neighboring topics. What a model is allowed to say is shaped by what it is given, which is the subject of grounding and hallucination. And how much can be carried forward across a conversation is bounded by the context window, covered in long context and memory.

Filter demonstrations and retrieved context

Examples

Before prompting
Include only examples this request is allowed to use.

Current data

Before prompting
Retrieve only authorized records.
Allowed prompt context

The model receives the filtered examples and task data.

In-context examples can contain sensitive information. Their use belongs inside the same access boundary as the rest of the prompt.

The direction the field is heading.

We describe the direction, not a roadmap of our own.

Example selection

From hand-picked to retrieved.

Moving from manually chosen examples toward retrieving the most useful demonstrations for each specific input, so the prompt adapts to the question.

Longer context

Many-shot becomes possible.

As the room in a prompt grows, including far more examples comes into reach. The tradeoff is real: more examples cost more compute and can dilute as well as help.

Clearer theory

Pinning down the mechanism.

Ongoing work tries to say what the model is actually doing when it learns in context, including views connecting it to inference over a latent task and to optimization-like behavior inside the forward pass. Kept open and honest.

Prompting and tuning

The line keeps moving.

Methods that sit between pure prompting and full fine-tuning continue to develop. We stay neutral on which a given product uses.

Reliability and safety

Discipline about what enters a prompt.

Because the prompt carries both the task and the data, the practice of keeping a prompt within what the asker may see only grows in importance.

The sources behind this page.

Keep reading.

Sibling explainers in the Research section.

Talk. Done.

Show a model the task, and the work follows. See what that feels like on a real call.

No app required. Just your phone number.