In Context Learning

Also known as: ICL, few-shot learning, prompt-based learning

In Context Learning
In-context learning is a capability of large language models to adapt their behavior based on examples or instructions provided inside the prompt at inference time, without any weight updates or retraining.

In-context learning is the ability of a language model to adapt its behavior from examples placed in the prompt at inference time, without any changes to its underlying weights.

What It Is

When you interact with a language model, you are not training it. The model’s internal parameters — the billions of numerical weights that encode everything it learned during training — are frozen. Yet the model can still adapt. Give it three examples of a task it has never explicitly been trained for, and it often performs that task correctly on the next input. That adaptation happens entirely inside the context window, in real time. This is in-context learning.

Think of it like a contractor reading a project brief before starting work. The contractor’s underlying skills don’t change between jobs, but their output changes dramatically based on what is in the brief. The context is temporary — when the job ends, the brief is gone. The next project starts fresh.

In-context learning matters because it is the mechanism that makes large language models genuinely flexible tools. Without it, every new task would require a new fine-tuned model. With it, you can steer a general-purpose model toward dozens of different tasks in the same session, just by changing what you put in the prompt.

The model achieves this by recognizing patterns in the examples you provide. If you show it three pairs of (customer complaint → formal apology email), it identifies the pattern: formal register, acknowledgment of the issue, resolution offer. When you then give it a fourth complaint, it applies that pattern without explicit instructions. The examples are doing the teaching.

This capability scales with model size. Smaller models struggle to pick up new patterns reliably from just a few examples. Larger models can generalize from one example, or even from pure instructions with no examples at all — a variant called zero-shot learning. The range from zero examples to many examples gives rise to the terms zero-shot, one-shot, and few-shot prompting, all of which are subsets of in-context learning.

In the context of role prompting — telling the model to behave as a specific expert persona — in-context learning is what makes the instruction stick within the session. When you prompt a model to act as a senior editor, the model reads that instruction, infers what senior-editor behavior looks like based on its training data, and applies that pattern across your subsequent requests. The persona is not stored anywhere. It lives in the context.

How It’s Used in Practice

The most common place people encounter in-context learning is in chat interfaces like Claude or ChatGPT, when they paste in examples of a desired output format before making their actual request. A product manager might paste in two example user stories before asking the model to generate ten more. A support team might paste in three sample responses in their brand voice before asking the model to draft replies to open tickets.

The examples act as an implicit specification. Instead of writing a long instruction describing every nuance of tone, structure, and vocabulary, you show the model what done looks like and let it infer the rest. This often produces better results than instructions alone, because some stylistic patterns are easier to demonstrate than to describe.

In role prompting specifically, in-context learning is what turns a one-line persona instruction into a sustained behavioral shift. The model doesn’t just read “You are a legal expert” and store it as a setting. It uses that instruction as an in-context example of how it should frame every subsequent response in the conversation.

Pro Tip: Longer example lists don’t always help. Two or three high-quality examples tend to outperform six mediocre ones. Spend your prompt budget on example quality, not quantity — and make sure your examples actually represent the output you want, not just a rough approximation of it.

When to Use / When Not

ScenarioUseAvoid
You want consistent output format across many items
You need the model to match a specific writing style or tone
The task is complex enough that instructions alone produce inconsistent results
You are prompting the model to adopt an expert persona
The task is simple and standard (summarize, translate, answer a question)
Your context window is already near its limit

Common Misconception

Myth: Giving the model examples in the prompt “teaches” it permanently — the model learns and retains the information for future sessions.

Reality: In-context learning is session-scoped and leaves no trace. The model’s weights are unchanged. When the conversation ends, everything in the context disappears. The next user who sends the same model the same base prompt starts with a completely blank slate. What the model “learned” from your examples existed only in working memory, not in long-term storage.

One Sentence to Remember

In-context learning lets you redirect a frozen model’s behavior without retraining it — but that redirection is temporary, lives only in the current context window, and vanishes the moment the session ends.

FAQ

Q: What is the difference between in-context learning and fine-tuning? A: Fine-tuning updates the model’s internal weights through additional training on new data. In-context learning changes model behavior only within a single context window, using examples in the prompt, with no weight updates at all.

Q: How many examples do I need for in-context learning to work? A: One to five well-chosen examples usually suffice. One example (one-shot) is often enough for pattern recognition; beyond five, returns diminish. The bottleneck is typically context window space, not example count.

Q: Does in-context learning work for role prompting and persona instructions? A: Yes — assigning an expert role is a form of in-context instruction without examples. The model infers the expected behavior from the role description and applies it throughout the conversation, as long as it stays in the context window.

Expert Takes

In-context learning is not the same mechanism as gradient descent. The model never updates its weights — it performs a kind of implicit Bayesian inference, treating the in-context examples as evidence and updating its distribution over outputs accordingly. This happens through the forward pass alone. The result looks like learning, but it is better described as structured conditioning: the model’s prior, shaped by pretraining, gets refined by the context it receives.

For anyone building on top of language models, in-context learning is the practical specification layer. Your examples in the prompt are your implicit schema — they define output format, tone register, and handling of edge cases more precisely than a paragraph of natural-language instructions. The discipline is in curating those examples carefully. One inconsistent example can introduce noise that degrades output quality across the entire request batch.

In-context learning is the reason general-purpose AI tools outcompeted narrow single-task tools so quickly. You don’t need a separate model for each task — you need a large enough model and a well-designed prompt. That shift has moved value from model specialization to prompt engineering and context design. The teams that figured this out early built workflows that others are still trying to catch up with.

In-context learning makes model behavior opaque in a specific way. The same base model can be conditioned by different users into very different behavioral patterns within a session — patterns the model provider neither authorized nor reviewed. When the input examples contain bias, manipulation, or harmful framing, the model faithfully generalizes from them. The capability that makes these models flexible is the same one that makes their runtime behavior hard to audit or constrain.