Papers
Topics
Authors
Recent
2000 character limit reached

Prompt Template & Example Selection

Updated 10 December 2025
  • Prompt Template and Example Selection is a methodology that designs structured inputs and selects exemplar cases to optimize LLM performance using minimal labeled data.
  • It employs techniques such as clustering, local retrieval, and ensemble search to improve template formatting and example diversity across various applications.
  • Automated optimization and rigorous evaluation of prompt-template-exemplar pairs drive measurable gains in tasks like classification, translation, and code generation.

Prompt Template and Example Selection encompasses a suite of methodologies for configuring input to LLMs so that maximal performance is achieved on downstream tasks, particularly when only small labeled datasets are available. Core dimensions include the explicit formatting of instructions and demonstrations (“prompt-template design”), algorithmic selection of in-context examples (“example selection”), the use of ensemble and automatic search techniques, and the evaluation and optimization of prompt-template-exemplar pairs. These mechanisms underpin modern prompt engineering, critical for adaptation and deployment of LLMs in areas such as e-commerce, code generation, translation, automated scoring, and classification.

1. Foundations of Prompt Template Design

Prompt templates encode the structure, verbalization, and formatting of inputs to LLMs. Template design directly affects output accuracy; poor choices can reduce output quality to chance-level (Voronov et al., 12 Jan 2024). Templates are specified across:

  • Input verbalizer, vI(x)\mathsf{v}_I(x): Defines how raw input x is introduced, e.g., “input: {}”, “sentence: {}”;
  • Output verbalizer, vO(y)\mathsf{v}_O(y): Specifies label phrasing, such as “label: {}”, “sentiment: {}.”;
  • Intra-separator: Delimiters between input and output, typically spaces or newlines;
  • Inter-separator: Delimiters between examples, e.g., blank lines or “### Example ###”.

In “Examples as the Prompt” (EaP) (Zeng et al., 14 Mar 2025), the template is a concatenation of:

[SYSTEM_PROMPT] Example 1: Input: {...} Output: {...} ... “Now you are given a new query: Input: {q} Output:”

For the lightweight variant EaPₗᵢₜₑ, the SYSTEM_PROMPT is dropped for a single anchor line.

In machine translation and other domains, prompt templates include explicit role descriptions, example pair enumeration, and directives for output formatting (e.g., requesting “only the translation result” in (Kakavand et al., 4 Oct 2025)).

2. Example Selection Algorithms

Selecting representative, relevant, and diverse in-context examples is essential for robust ICL. Methods are broadly categorized as:

2.1 Clustering-Based Global Selection

EaP (Zeng et al., 14 Mar 2025) uses k-means clustering over feature embeddings (TF-IDF or LLM-based) of a labeled pool E\mathcal{E}:

J=j=1KxCjϕ(x)μj2J = \sum_{j=1}^K \sum_{x \in C_j} \|\phi(x) - \mu_j\|^2

Each cluster centroid yields a global exemplar ej=argminxCjϕ(x)μje^*_j = \arg\min_{x \in C_j}\|\phi(x)-\mu_j\|.

2.2 Local (Per-Query) Retrieval

For each query qq, embed qq as u=ϕ(q)u = \phi(q), then select top-MM nearest examples from E\mathcal{E} using:

sim(u,v)=uvuv\mathrm{sim}(u,v) = \frac{u\cdot v}{\|u\|\cdot\|v\|}

with implementations leveraging FAISS or RapidFuzz for sublinear nearest neighbor search.

2.3 Hierarchical/Quality-Driven Methods

TreePrompt (Kakavand et al., 4 Oct 2025) iteratively asks the LLM to label example pairs in a tree structure (good, neutral, bad), then expands on high-quality branches via k-NN. Adaptive Few-Shot Prompting (AFSP) can merge similarity scores from multiple embedding spaces.

2.4 Spectral Methods

For tabular data, (Han et al., 25 Jun 2025) computes similarity via Jaccard index on LLM tokenizations, builds a kk-NN graph, and uses the Laplacian eigengap to infer the minimal number of demonstration clusters required:

k=argmax1i<n(λi+1λi)k = \arg\max_{1 \leq i < n}(\lambda_{i+1}-\lambda_i)

2.5 Mutual Information Maximization

Templates are selected to maximize estimated mutual information I(X;Y)=H(Y)H(YX)I(X;Y) = H(Y) - H(Y|X) over an unlabeled pool, with only LM calls required (Sorensen et al., 2022). This reliably identifies high-quality templates without ground-truth data.

3. Automated Prompt and Template Optimization

Recent work eliminates manual prompt engineering via automatic, data-driven prompt generation.

  • Adaptive Selection of Prompting Techniques (Ikenoue et al., 20 Oct 2025): Task clusters are formed via semantic embedding and k-means. Each cluster is mapped to a set of prompt elements (“techniques”) stored in knowledge-base JSON. User-provided descriptions are embedded, matched to clusters, and fused into prompts with dynamically weighted techniques according to historical frequency and performance.
  • Input-Output Coverage Maximization: For tasks requiring few-shot exemplars, select example subsets EE^* by maximizing the sum of pairwise similarities, sorted by difficulty or diversity.
  • Successive Halving for Template Search (Han et al., 10 Jun 2025): Prompt candidates are evaluated iteratively on increasing validation sets, halving candidates at each round, until the best template remains.
  • Blueprints for Reasoning (Han et al., 10 Jun 2025): Structured, reusable high-level guides (“blueprints”) are generated for SLMs by LLMs, selected by validation accuracy, and refined via automatic prompt optimization (APO).

4. Empirical Performance and Evaluation Metrics

Prompt-template and example selection strategies result in statistically significant improvements:

Approach Domain Best Reported Gain
EaP/EaPₗᵢₜₑ E-commerce classification Navigation Pos Prec 0.8910 vs 0.8198 (+8.9%), throughput +71.6% (Zeng et al., 14 Mar 2025)
TreePrompt+AFSP English→Persian MT COMET improvement 0.01–0.02 over vanilla KNN/AFSP (Kakavand et al., 4 Oct 2025)
Spectral/Graph Tabular classification “Stable” performance close to random-best across multiple datasets and LLMs (Han et al., 25 Jun 2025)
PromptRefine Indic ICL Token-F1 +8.26 vs CEIL; chrF₁ +3.28 in MT (Ghosal et al., 7 Dec 2024)
Complexity-based NER tagging +5 F1 GPT-4 CoNLL2003; +28.85 in GPT-j (Adiga et al., 6 Mar 2024)
MI-based General NLP tasks Achieves 90% of gap from mean to best prompt accuracy, zero labels needed (Sorensen et al., 2022)
Automated Gen. BBEH +4.1pp arithmetic mean over original (Ikenoue et al., 20 Oct 2025)
AES Essay scoring (GPT) Example selection enables GPT-3.5 to outperform some GPT-4; robust template orderings matter (Yoshida, 28 Nov 2024)

Metrics include precision/recall, BLEU/ROUGE, Macro-F1_1, QWK, COMET, and throughput (items/sec).

5. Systematic Taxonomies and Best-Use Practices

Prompt-with-Me (Li et al., 21 Sep 2025) proposes a four-dimensional taxonomy for LLM-driven software engineering prompts:

  • Intent: Objective (e.g. “Code Generation”, “Review”).
  • Author Role: Persona/discipline of the author.
  • SDLC Stage: Lifecycle phase.
  • Prompt Type: Structural paradigm (template, zero-shot, few-shot).

Automatic classification (hybrid ML: MLP and Random Forest) ensures near-real-time tagging for structured management, with downstream performance evident in improved developer adoption, reduced duplication, and enhanced reproducibility.

Best-practice highlights across studies:

6. Limitations, Caveats, and Future Directions

Despite consistently positive impacts, several limitations are noted:

  • Template sensitivity remains high; optimal formatting and example selection do not universally transfer (Voronov et al., 12 Jan 2024).
  • Example selection can introduce majority/recency bias (AES), varying by model/version (Yoshida, 28 Nov 2024).
  • Automated prompt optimization (e.g. via instruction refinement) exceeds example selection in effect size, but combining both gives only incremental benefit and requires matching train/test policies (Wrzalik et al., 9 Dec 2024).
  • For mutual information-based template selection, low MI values are indicative of model incapability—not a guarantee of optimality (Sorensen et al., 2022).
  • Empirical gains are task- and domain-dependent; ablation and adaptation per deployment are recommended.

Emerging directions include fine-grained, context-length-aware selection, ensembling of prompt-generation strategies, integration with software versioning and health monitoring, and robust multilingual alignment for cross-resource ICL.

7. Representative Implementations and Pseudocode Overview

The following table summarizes key algorithms for template and example selection:

Name Selection Principle Pseudocode/Procedure Location
EaP Global/Local K-means + ANN (Zeng et al., 14 Mar 2025), Section 2
TreePrompt LLM-labeled tree + K-NN/AFSP (Kakavand et al., 4 Oct 2025), Sec. 2-3
Spectral Demonstration Eigengap over token Jaccard (Han et al., 25 Jun 2025), Sec. 3-5
MI-Max Template Mutual Information over unlabeled (Sorensen et al., 2022), Sec. 3
Multi-prompt Evaluation IRT + plug-in estimator (Polo et al., 27 May 2024), Algorithm 1
Complexity-based NER Weighted C_sent (Adiga et al., 6 Mar 2024), Section 3
Automated Prompt Generation Coverage max, cluster-based (Ikenoue et al., 20 Oct 2025), Sections 3-4

By systematically combining taxonomized templates, robust example selection, and automated optimization, practitioners can derive high-performing prompt configurations that generalize across real-world tasks, models, and operational constraints.

Whiteboard

Follow Topic

Get notified by email when new papers are published related to Prompt Template and Example Selection.