Join our Newsletter — 33% off our NHI Course
Home› Glossary› Agentic AI & Autonomous Identity› In-context learning
Agentic AI & Autonomous Identity

In-context learning

← Back to Glossary
By NHI Mgmt Group Updated October 30, 2026 Domain: Agentic AI & Autonomous Identity

A model’s ability to adapt its output from examples placed in the prompt without changing its underlying weights. The behaviour is temporary but operationally meaningful, because the session context can steer what the model produces for the duration of inference.

How in-context learning works

In-context learning is the model behaviour that lets a system use examples, instructions, or demonstrations inside the prompt to shape its output for that single inference run. The model is not updated, so the effect is temporary, but it can still be strong enough to redirect style, structure, classification, or task interpretation.

This makes in-context learning different from training or fine-tuning. The prompt acts as the immediate working context, which means the quality, order, and consistency of the examples matter. A model may generalise a pattern from just a few well-formed examples, but it can also overfit to a narrow prompt pattern or follow a misleading cue if the context is ambiguous.

Why in-context learning matters operationally

For practitioners, the main value is flexibility. Teams can adapt a model to a new format, domain, or policy boundary without changing weights or rebuilding the model. That makes it useful for rapid prototyping, dynamic workflows, and situations where the task framing changes frequently.

The trade-off is that the behaviour is only as reliable as the live prompt context. If examples are inconsistent, poorly scoped, or contaminated by irrelevant content, the model may reproduce the wrong pattern with confidence. In practice, in-context learning is often less about the model “understanding” a task in a durable sense and more about whether the prompt provides a strong enough short-term signal.

Because the mechanism is session-bound, it is also sensitive to context length, prompt precedence, and any competing instructions already present in the conversation. Small changes in the prompt can materially change the output, which is one reason teams treat prompt design as an operational control rather than a cosmetic layer.

Where in-context learning is strongest

In-context learning is especially useful for tasks that can be demonstrated with a small number of examples, such as label mapping, output formatting, extraction patterns, or role-specific response style. It is also valuable when the desired behaviour is easier to show than to encode as a static rule set.

Its limits appear when the task requires persistent memory, stable policy enforcement, or strong guarantees across many runs. Since the learned behaviour is not retained after the session, it cannot replace durable model adaptation or a governed control plane for production decisioning.

It is also worth distinguishing between adaptation and authority. A model can appear to follow a prompt example very well while still failing to verify facts, enforce policy, or respect hidden constraints. In other words, in-context learning can shape output, but it does not by itself create trustworthy ground truth.

Prompt design and evaluation considerations

Good use of in-context learning depends on how examples are selected and tested. Examples should be representative, internally consistent, and close to the target task, because the model will often infer a pattern from whatever is most salient in the context window.

Evaluation should therefore check more than surface accuracy. Practitioners need to see whether the model follows the intended pattern, whether it remains stable when examples are reordered or trimmed, and whether unrelated text changes the result. That is especially important when the output affects downstream automation or user-facing decisions.

In security-sensitive settings, the prompt itself becomes part of the operational boundary. If examples can be influenced by untrusted input, the model may absorb malicious instruction patterns or leak behaviour across turns. That is why prompt hygiene, provenance of examples, and careful boundary-setting matter as much as the model choice.

Risk and Threat Considerations

In-context learning creates a prompt-time attack surface because the model will often treat nearby examples as instructional truth. If an attacker can influence the context, they may steer output, weaken guardrails, or induce behaviour that looks legitimate inside the session even though no model weights changed.

Failure mechanism: Prompt injection, example poisoning, or instruction conflict can cause the model to follow the wrong pattern, disclose sensitive context, or generate actions that reflect attacker-supplied cues rather than the intended task boundary.

Impact: The result can be unsafe outputs, data leakage, policy bypass, or incorrect downstream automation, especially when the model output is consumed by another system or used to make operational decisions.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATLAS and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST AI RMF, NIST CSF 2.0 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST AI RMFGovernIn-context learning affects AI governance, evaluation and trustworthiness controls.
Recommendation — Establish prompt governance and evaluation controls for session-time model adaptation.
MITRE ATLASAdversarial AI ThreatsPrompt injection and context poisoning are core adversarial AI techniques.
Recommendation — Model prompt-time manipulation as an adversarial AI risk and test for context poisoning.
NIST CSF 2.0PR.DS-10 — Confidentiality of Data at RestPrompt context can expose sensitive input material during model use.
Recommendation — Restrict sensitive prompt content and protect contextual data shared with models.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationPrompt content must be validated to reduce malicious or malformed instruction input.
Recommendation — Validate and constrain prompt inputs before they influence model behaviour.
OWASP Agentic AI Top 10ASI06 — Memory & Context PoisoningThe term directly concerns context-driven behavioural steering in AI systems.
Recommendation — Harden context handling to reduce poisoning of model behaviour through prompts.

Practitioner Guidance

What to watch for: Treat example selection, prompt ordering, and source trust as part of the control surface. If a task depends on in-context learning, keep demonstrations tightly scoped, review them for ambiguity, and test how the model behaves when context is noisy or partially adversarial.

Governance implication: Teams should decide which prompts are allowed to shape behaviour, who can edit them, and how prompt changes are reviewed. That governance matters because the prompt can function like a live, temporary policy layer for the duration of inference.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 30, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org