Evaluating a prompt on the same examples used to choose it biases its reported loss downward, a phenomenon we call context overfitting. We study this gap by comparing a chosen prompt's deployment risk with its selected score, the empirical loss over the $k$ examples used in its evaluation, whether reused validation queries or demonstrations scored inside the prompt itself. Every adaptive pipeline is captured by a transcript fixing both the predictor and the scored indices. Pairing that transcript with an independent copy of the scoring store defines a ghost law under which the selected score concentrates at scale $1/\sqrt{k}$; transporting back to the actual pipeline charges an information price, the selection capacity $κ$, yielding expected, high-probability, and PAC-Bayesian certificates at scale $\sqrt{κ/k}$. We prove that this rate is minimax optimal for every ambient store size $n \ge k$, establish its exact leading constant in the moderate-capacity regime, and show that without a capacity constraint deterministic cherry-picking forces a nearly vacuous $1 - O(k/n)$ correction. A compositional capacity calculus budgets $κ$ directly from pipeline logs across candidate menus, data-dependent shortlists, noisy score releases, and multi-round edits. Optimizing the PAC-Bayesian certificate itself yields stability-constrained adaptive randomization (SCAR), a Gibbs selector that trades empirical fit against divergence from a fixed prior. Across 24,000 selection trials on Banking77 spanning 64 prompt recipes and two model families (Qwen2.5-7B-Instruct and GPT-4.1-mini), empirical coverage is 100%, and SCAR achieves the tightest certified risk at every sample size, certifying gains over zero-shot deployment risk on more than 99% of validation draws from $k=64$ and $k=128$ examples, respectively.
翻译:暂无翻译