In-Context Learning (ICL) is an emergent capability of large language models where the model performs a novel task by conditioning solely on a prompt containing a few input-output examples, without any gradient updates or parameter fine-tuning. The model infers the task pattern from the provided demonstrations and applies it to a new query, effectively learning on the fly during a single forward pass.
Glossary
In-Context Learning (ICL)

What is In-Context Learning (ICL)?
In-context learning is a model's emergent ability to adapt to a new task by conditioning on a prompt containing a few input-output demonstrations, without any gradient updates or fine-tuning of its parameters.
This phenomenon relies on the Transformer's attention mechanism to identify analogical mappings between the provided demonstrations and the target query. ICL is distinct from few-shot prompting only in emphasis—ICL describes the underlying learning mechanism, while few-shot prompting describes the technique. Performance is sensitive to demonstration ordering, label balance, and format consistency within the context window.
Key Characteristics of In-Context Learning
In-Context Learning (ICL) represents a fundamental shift in machine learning paradigms, where a model adapts to a novel task purely through conditioning on a structured prompt, bypassing the traditional weight update cycle. The following cards dissect the core properties, limitations, and operational mechanics that define this capability.
Gradient-Free Adaptation
The defining characteristic of ICL is the complete absence of parameter updates. Unlike fine-tuning, which requires backpropagation and weight modification, ICL operates entirely during the forward pass. The model's pre-trained weights are frozen. The prompt, containing demonstrations and a query, acts as a transient program that reconfigures the model's attention patterns to perform the specified task. This means the model can switch between translation, summarization, and code generation instantly without any computational overhead for retraining, making it ideal for dynamic, low-latency environments where task definitions change rapidly.
Emergent Property of Scale
ICL is not explicitly trained for; it emerges unpredictably as model and data scale increase. Smaller models exhibit minimal or no ICL capability, while large frontier models demonstrate sophisticated reasoning from prompts. This emergence is linked to the model's ability to form induction heads during pre-training—circuits that recognize and copy abstract patterns. The phenomenon suggests that large-scale autoregressive training on diverse corpora implicitly teaches the model to perform Bayesian inference over latent task concepts, treating the provided demonstrations as conditioning evidence to infer the correct input-output mapping.
Prompt Format Sensitivity
ICL performance is notoriously brittle and highly sensitive to the specific formatting of the prompt. Minor changes in demonstration ordering, label balance, or the surrounding template can cause significant accuracy swings. Key factors include:
- Label Balance: A skewed distribution of classes in the few-shot examples can bias the model.
- Format Consistency: The input-output mapping must follow a rigid, predictable pattern.
- Recency Bias: The model often weights the final demonstration most heavily. This sensitivity implies that the model is performing a form of pattern matching rather than robust abstract reasoning, requiring rigorous prompt engineering to stabilize outputs.
Locality of Information Processing
ICL relies on the Transformer's attention mechanism to create a direct information pathway between the demonstration examples and the query. The model effectively constructs a local learning algorithm within its context window. The key-value pairs from the demonstrations act as a temporary associative memory. This explains the recency bias and lost-in-the-middle effects: tokens at the end of the prompt have a shorter attention distance to the query token, granting them higher effective weight. Understanding this mechanism is critical for optimizing prompt structure to ensure the most relevant demonstrations are placed in high-attention positions.
Task Induction vs. Task Recognition
A critical distinction exists between whether ICL truly learns a new task from scratch or merely recognizes a known task from pre-training data. Evidence suggests a hybrid mechanism. The model uses the prompt to locate an existing skill within its parameter space rather than synthesizing a completely novel algorithm. If a task was heavily represented in the training data, ICL serves as an efficient retrieval cue. For genuinely novel tasks, performance degrades significantly, revealing the limits of ICL as a reasoning engine. This positions ICL as a powerful retrieval and adaptation mechanism, not a replacement for true out-of-distribution learning.
Computational Cost Profile
While ICL eliminates training costs, it shifts the computational burden entirely to inference. The entire prompt, including all demonstration examples, must be processed in a single forward pass. This creates a linear scaling cost with the number of shots. For long-context models, the quadratic complexity of self-attention can make large-shot ICL prohibitively expensive in terms of latency and compute. This cost profile has driven the development of complementary techniques like KV-Cache optimization and prompt compression, which aim to amortize the cost of the static demonstration prefix across multiple queries.
Frequently Asked Questions About In-Context Learning
In-context learning represents one of the most significant emergent behaviors of large language models, allowing them to adapt to novel tasks through prompt conditioning alone. These answers address the core mechanisms, limitations, and engineering considerations for practitioners building systems that rely on ICL.
In-context learning (ICL) is an emergent capability of large language models where the model adapts to a new task by conditioning on a prompt containing a few input-output demonstration examples, without any gradient updates or fine-tuning of its parameters. The mechanism works by the model implicitly constructing a task-specific inference function within its attention mechanism at inference time. When a prompt includes several (input, output) pairs followed by a query input, the model's self-attention layers learn to map the pattern from the demonstrations to the query. Research suggests this occurs because Transformer attention heads can implement gradient descent-like optimization internally, effectively learning a linear model from the provided examples within the forward pass. Unlike few-shot prompting, which is a specific application, ICL describes the broader phenomenon of the model extracting patterns, formats, and task definitions directly from the prompt context. This capability emerges primarily at scale, becoming reliable only when models exceed certain parameter thresholds, and is heavily influenced by the distribution of the pretraining data, which often contains naturally occurring sequences of related examples.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the ecosystem of concepts surrounding In-Context Learning, from the mechanisms that enable it to the prompting techniques that exploit it.
Few-Shot Prompting
The primary applied technique for In-Context Learning, where a small number of complete input-output demonstrations are prepended to the prompt. The model conditions on these examples to infer the task pattern, mapping, and desired output format without any weight updates. Performance typically scales with the number of examples until the context window is saturated.
Attention Mechanism
The core architectural enabler of ICL. Self-attention layers compute pairwise relevance scores between all tokens in the context window, allowing the model to dynamically attend to the provided demonstrations. Research suggests that Transformer attention heads can implicitly form induction heads that perform a primitive form of in-context gradient descent during the forward pass.
Context Window
The maximum token capacity of an LLM's working memory, defining the hard upper limit for ICL demonstrations. A larger context window allows for more few-shot examples or the inclusion of entire documents for retrieval-style ICL. Architectures using RoPE or ALiBi enable superior context length extrapolation beyond training lengths.
Retrieval-Augmented Generation (RAG)
A complementary paradigm that dynamically retrieves relevant documents and prepends them to the prompt. While distinct from pure ICL, RAG relies on the same in-context conditioning mechanism to ground generation in the retrieved text. The combination of semantic search for retrieval and ICL for reasoning creates a powerful few-shot learning pipeline without fine-tuning.
Lost-in-the-Middle
A critical failure mode of ICL where information placed in the center of a long context is significantly less likely to be utilized than information at the beginning (primacy bias) or end (recency bias). This directly impacts how demonstrations should be ordered in a prompt, with the most critical examples placed at the extremes of the context window.
Prompt Compression
Techniques to condense lengthy ICL demonstrations into denser representations to reduce token costs and latency. Methods include LLMLingua, which uses a small language model to remove non-essential tokens, and AutoCompressors, which summarize long demonstration sets into compact soft prompts, preserving task-relevant information while freeing context window space.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us