Papers
Topics
Authors
Recent
2000 character limit reached

Few-Shot Prompting

Updated 28 November 2025
  • Few-shot prompting is a technique that leverages in-context learning with a few demonstration pairs to adapt pretrained models without parameter updates.
  • It relies on precise prompt engineering, including example selection, ordering, and strict output schemas to minimize errors and improve task performance.
  • This approach is cost-efficient and highly adaptable, though performance may plateau or decline with over-prompting and sensitive template designs.

Few-shot prompting is a methodology for adapting pretrained models—especially LLMs—to new tasks or domains using a minimal set of labeled examples provided as context. Unlike conventional fine-tuning, few-shot prompting leverages the model’s in-context learning capabilities, obviating the need for parameter updates on the target dataset. This paradigm has demonstrated strong performance across NER, classification, generation, translation, reasoning, action recognition, dialog, database querying, and other domains. Central to its effectiveness are prompt engineering, example selection and ordering, output control, and architectural adaptations that modulate stability and robustness.

1. Formulation and Implementation Principles

Few-shot prompting operates by constructing a prompt composed of kk input–output demonstration pairs, followed by the target input. The model is conditioned to emulate the mapping seen in the demonstrations, either via natural language, programmatic outputs, JSON, or specialized schema. The canonical mathematical formulation is, for input xx and prompt E={(xi,yi)}i=1kE = \{(x_i, y_i)\}_{i=1}^k, outputting y^=fθ(Prompt)\hat{y} = f_\theta(\textrm{Prompt}), where Prompt\textrm{Prompt} encodes EE and xx, and fθf_\theta is the forward operator of an LLM with frozen weights (Zeghidi et al., 28 Aug 2024, Dong et al., 2023, Shi et al., 2022, Wang et al., 2022, Ji et al., 2023, Zheng et al., 2021, Kumar et al., 15 Mar 2025, Wang et al., 2022, Leite et al., 3 Apr 2024, Liu et al., 30 Apr 2024, Toukmaji, 9 Mar 2024, Sweidan et al., 24 Sep 2025, Schick et al., 2021, Tang et al., 3 Jan 2025, Tang et al., 16 Sep 2025, Köksal et al., 2022, Li et al., 2023, Chen et al., 2023, Jie et al., 2023).

Prompt templates vary by application. In NER, templates include a tokenization table to avoid offset hallucinations, strict output schema (e.g., JSON with keys: start, end, text, label), and explicit instance instructions. For classification, templates transform inputs into cloze statements, sometimes with label verbalizers, multi-label mappings, or relevance-estimation pairs. Generation tasks (text, QA, translation, code) employ sequence-to-sequence instructions with exemplar mappings, schema controls, and domain-specific system prompts. Vision and multimodal extensions inject semantic-of-class prompts or action-proposal sets into feature extractors.

2. Prompt Engineering: Templates, Schema, and Output Control

Prompt engineering encompasses both template design and output format imposition. Precise template structure is critical: tokenization tables, class-list logic, strict output schemas (e.g., enforced JSON), and explicit instructions (“do not invent offsets”, “provide only SQL queries”) significantly reduce output errors, format violations, and spurious attribute hallucinations. In NER for French, injecting token tables eliminates offset hallucinations (>50% bogus offsets otherwise); strict JSON reduces malformed output rates from ~5% to <1% (Zeghidi et al., 28 Aug 2024). In insights discovery, Contextual Few-Shot Prompting dynamically retrieves the kk most semantically similar examples to the user query, maximizing answer relevance and supporting robust Text-to-SQL translation with clause-wise matching and execution accuracy (Kumar et al., 15 Mar 2025).

Wording identity (“Identify all entities of types X, Y, Z” vs. “Extract spans and label them”) has minor but sometimes measurable impact (<2 pp F1 in NER). Output schema guidance (“JSON” vs. “list of dictionaries”) is more impactful, increasing error rates by up to +3 pp when omitted. Instruction placement and component ordering (e.g., template blocks that distinguish context vs. grounding in dialog) affect attention in unidirectional architectures (Zheng et al., 2021).

3. Example Selection, Ordering, and Over-prompting

Selection of demonstration examples is pivotal. Exemplars containing all target classes or attributes provide comprehensive supervision, but simple random or stratified sampling may be suboptimal in domain-specialized tasks. Semantic embedding (SimCSE + kNN), TF-IDF, or hybrid LLM-driven retrieval methods substantially improve relevance and performance compared to random sampling, especially in classification and translation (Tang et al., 3 Jan 2025, Tang et al., 16 Sep 2025). In translation, the Adaptive Few-Shot Prompting (AFSP) framework retrieves the top-kk semantically similar source-target pairs using hybrid dense/sparse/multi-vector ranking on the LLM’s own embeddings, yielding up to +7 BLEU improvement over static few-shot baselines; k=3k=3 is generally optimal, with performance degrading at k>4k>4, evidencing diminishing returns from excessive prompting.

Ordering matters: nested alternation in class-balanced pools for Alzheimer’s detection stabilizes calibration and reproducibility. Over-prompting is formally defined as the decline in performance f(N)f(N) above an optimal NN^*; empirical curves show accuracy peaking at NN^* (e.g., 40–120 examples depending on LLM) then declining or plateauing. Excessive examples may confuse the model or induce context-window truncation, particularly in tasks with long-form inputs (e.g., summarization, code) (Tang et al., 16 Sep 2025).

4. Robustness, Stability, and Active Data Selection

Prompt instability—high run-to-run variance under different initializations, template phrasings, or example sets—has motivated several architectural and training advances. StablePT separates hard and soft prompts into parallel streams, linking them via cross-attention and supervised contrastive loss, yielding +6.97% accuracy and −1.92 points std deviation on seven datasets (Liu et al., 30 Apr 2024). MEAL integrates multiprompt finetuning, prediction ensembling, and Inter-Prompt Uncertainty Sampling with Diversity (IPUSD) active learning, reducing both prompt-selection and run variance (+2.3 pp over PET, std.dev halved). These schemes exploit multiple templates, parameter averaging, candidate clustering, and prompt disagreement (Prompt-Pair KL) to stabilize performance. Discrete human-readable prompts, especially with semantic initialization, prove more reliable than random or continuous variants in dialog and grounded text generation (Zheng et al., 2021).

Policy-gradient–based discrete prompt optimization utilizes reinforcement learning to match input embeddings to task-aligned prompts, with prompt set construction via multi-round dialogue alignment with GPT-4 and supervised unsupervised entropy metrics (SUE). This procedure outperforms prior RLPrompt baselines with substantially smaller policy networks (~0.67% of PLM parameters) (Li et al., 2023).

5. Domain Adaptation, Control, and Generalization

Few-shot prompting demonstrates rapid adaptability to unseen entity types, domains, and languages. In NER, changing the entity list in the instruction block enables GPT-4o to extract novel categories (Organizational, Date) with no further training—though precision drops. For low-resource cross-lingual transfer, direct prompting in the target language with just 1–4 examples outperforms both translation-based schemes and high-cost language-adaptive fine-tuning across summarization, classification, and NER, with statistical significance for all shot counts (Toukmaji, 9 Mar 2024). Multi-task joint prompt-tuning (UPT) with auxiliary selective masked-language modeling (KSMLM) yields +1–2% gains with strong cross-dataset generalization, particularly for small PLMs (Wang et al., 2022). Controlled generation (e.g., explicitness, narrative elements, style) is effected by attribute labeling in the demonstration block and clear instruction tokens, with downstream evaluation confirming semantic steering and explicitness control (Leite et al., 3 Apr 2024). Knowledge prompting for few-shot action recognition uses large-scale language-derived proposal sets to prompt frozen vision-LLMs, achieving SOTA with ~0.1% training overhead compared to video backbone fine-tuning (Shi et al., 2022).

6. Evaluation: Performance, Efficiency, and Limitations

Few-shot prompting (e.g., GPT-4o, token-level F1_1=0.70 in NER) trails fully supervised models by 20–25 F1_1 points, most pronounced on recall due to under-generation. For tabular insights discovery, contextual few-shot prompting lifts execution accuracy on Spider from 53% (fixed) to 71% (CFS), with largest gains on medium/hard queries. Dynamic program prompting for numerical reasoning matches complex multi-step reasoning with automatic program synthesis and execution, surpassing fixed CoT and PAL schemes, especially in domains requiring programmatic composition (MathQA: 61.7% vs. 30% PAL) (Jie et al., 2023).

Few-shot prompting is highly compute- and cost-efficient compared to parameter-updating approaches. Direct prompting requires only inference passes, no extra annotation, and achieves robust adaptation, especially when combined with best-practice retrieval and schema control. However, limitations persist: scenario-dependent recall, persistent boundary errors, prompt sensitivity, no native handling of nested entities, and plateaued gains—or even performance degradation—at excessive shot counts. Data quality (representativeness, noise), schema specification, and context window constraints directly influence utility.

7. Outlook and Best Practices

Future directions include extending stable and active prompting techniques to generation and multi-label domains; improving automatic template search and learned verbalizers; integrating agentic modules for conversational/cross-modal use; incorporating chain-of-thought and multi-step reasoning for complex compositional tasks; and expanding attribute-specific control via prompt construction and downstream evaluation. Practitioners are advised to use nearest-neighbor or TF-IDF–driven example selection, strict schema and output specification, multiple prompt averaging, class and attribute stratification, and to empirically estimate the optimal shot count to circumvent over-prompting.

Few-shot prompting now enables rapid scaling of extraction, classification, generation, and comprehension tasks with minimal labeled data, and with careful engineering and selection protocols, approaches the reliability and effectiveness of fully supervised systems across remarkable task diversity.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (19)
Slide Deck Streamline Icon: https://streamlinehq.com

Whiteboard

Forward Email Streamline Icon: https://streamlinehq.com

Follow Topic

Get notified by email when new papers are published related to Few-Shot Prompting.