Few-shot fallback can include the evaluation document in its own prompt

Author: sdivyanshu90Created Sep 12, 2026Updated Sep 28, 2026

Problem

When a task has no configured fewshot_split, ConfigurableTask.fewshot_docs() falls back to training, validation, and finally test documents. For a test-only task, this means few-shot examples come from the same split being evaluated.

However, fewshot_context() passes the current document to the sampler only when fewshot_cfg.split == test_split. In the fallback case fewshot_cfg.split remains None, even though the resolved pool is the test split, so the sampler receives eval_doc=None.

Reproduction

Create a three-document test-only task, set num_fewshot=2, seed the few-shot sampler with 1234, and build each document's few-shot context. Two of the three resulting prompts contain the evaluated document's own question and gold answer as a demonstration. For example:

Q1 A1

Q0 A0

Q0

The final Q0 is the evaluated prompt, while Q0 A0 appears immediately beforehand as a few-shot example.

Impact

This is silent evaluation contamination. The model can see the gold answer for the item being scored, potentially inflating results. It is also seed-dependent, so repeated evaluations can appear inconsistent. Any task whose few-shot fallback resolves to its evaluation split is affected when users request nonzero few-shot evaluation.

Root cause

The exclusion decision compares configured split fields rather than the effective split selected by the fallback logic. The sampler already supports excluding an evaluation document, but the caller does not supply it in this case. Validation-only tasks using the validation split for both fallback few-shot examples and evaluation have the same structural problem.

Expected behavior

Whenever the effective few-shot pool is the same split used for evaluation, the current evaluation document must be passed to the sampler and excluded. Explicit sample lists and genuinely separate training or validation pools should retain their current behavior.

Proposed resolution

Resolve the effective few-shot source using the same precedence as fewshot_docs(), compare it with the effective evaluation split, and pass eval_doc when they match. Add regression coverage for fallback-to-test, fallback-to-validation, and a separate few-shot split.

Source: EleutherAI/lm-evaluation-harness