What Is In-Context Learning in LLMs?

Learning from examples in the prompt — without updating any model weights.

Ad placeholder (leaderboard)

What in-context learning means

In-context learning (ICL) is the ability of a large language model to perform a new task by following examples or instructions placed directly in its prompt — without any change to the model’s underlying weights. You show the model what you want inside the context window, and it generalises from those examples to your actual query. This is the mechanism behind “few-shot prompting” and is one of the defining capabilities of modern LLMs like GPT, Claude and Gemini.

How it differs from training

Traditional machine learning trains a model by adjusting millions or billions of parameters using gradient descent. In-context learning does none of that. The model is already trained and frozen; ICL happens at inference time. The examples you provide live only in the current prompt and are forgotten the moment the request completes. This makes ICL fast and cheap to experiment with — you change behaviour by editing text, not by retraining.

Zero-shot, one-shot and few-shot

These terms describe how many examples you include:

  • Zero-shot — just an instruction: “Classify this review as positive or negative.”
  • One-shot — the instruction plus a single worked example.
  • Few-shot — the instruction plus several examples showing the input/output pattern.

More examples generally improve consistency, especially for formatting and edge cases, but the gains flatten out and each example consumes context-window tokens you are paying for.

Why it works

Researchers do not have a single complete answer, but the leading view is that a heavily pretrained model has internalised a vast range of patterns during training. The prompt examples act as a task specification: they tell the model which of its existing capabilities to apply and what output shape to produce. Some studies suggest attention layers can implement something like a tiny optimisation step on the in-prompt examples, effectively “learning” within a single forward pass. The mechanism is still debated, but the practical effect is reliable.

What affects ICL quality

A few factors consistently change results:

  • Example relevance — examples close to your real input help most.
  • Example order — ordering matters, and the final example often carries extra weight, so end on a representative case.
  • Label balance — for classification, avoid skewing examples toward one label.
  • Format consistency — keep the input/output template identical across all examples so the model has a clean pattern to copy.

Used well, in-context learning lets you adapt a general model to a specific task in seconds — no fine-tuning, no infrastructure, just a well-constructed prompt.

Ad placeholder (rectangle)