Abstract
Large language models (LLMs) can be influenced by harmful or irrelevant context, which can significantly harm model performance on downstream tasks. This motivates principled designs in which LLM systems include built-in mechanisms to guard against such "garbage in, garbage out" scenarios. We propose a novel approach to limit the degree to which harmful context can degrade model performance. First, we define a baseline "safe" behavior for the model — the model's performance given no context at all (zero-shot). Next, we apply distribution-free risk control (DFRC) to control the extent to which the user-provided context can decay performance below this safe zero-shot baseline. We achieve this by leveraging dynamic early exit prediction, ignoring later attention heads that attend the most to the unsafe inputs. Finally, we propose modifications to DFRC that allow it to both control risk for harmful inputs and leverage performance and efficiency gains on helpful inputs. We present both theoretical and empirical results across 9 tasks spanning in-context learning and open-ended question answering, showing that our approach can effectively control risk for harmful context and simultaneously achieve substantial computational efficiency gains with helpful context.
Introduction
In-context learning (ICL) has revolutionized how we interact with Large Language Models (LLMs), allowing them to adapt to new tasks through a few examples in the prompt. However, this adaptability introduces a significant vulnerability: corrupted context. When provided with incorrectly labeled examples or misleading information, an LLM's performance can degrade significantly, often falling below its own "zero-shot" baseline (performance without any context).
This phenomenon is often attributed to "overthinking" in deeper layers. While early layers may capture the general task, deeper layers tend to over-index on the specific (and potentially incorrect) details of the provided context, overriding the model's robust internal biases.
Methodology
To mitigate the risks of corrupted context, we propose a framework that combines early-exiting with distribution-free risk control (DFRC). Our approach rests on three pillars:
- Safe Context-Aware Predictor: We utilize an early-exit architecture where the model can stop computation at any intermediate layer if its confidence exceeds a threshold $\lambda$. Crucially, if the model reaches the final layer without meeting this threshold, it defaults to a zero-shot fallback, effectively ignoring the potentially harmful context.
- Context-Aware Loss Function: We define a loss $\ell_c$ that measures the performance delta between the early-exit model (with context) and the full model (zero-shot). This allows us to treat performance gains from helpful context as "negative loss" and performance drops from harmful context as "positive loss."
- Risk Transformation for Learn-then-Test (LTT): Standard risk control frameworks like LTT require losses to be bounded within $[0, 1]$. To accommodate our context-aware loss, which can be negative, we introduce a Risk Transformation method. This maps the loss into a valid range for statistical calibration while ensuring that the final threshold $\lambda$ maintains the desired safety guarantees relative to the zero-shot baseline.
Experimental Evaluation
We evaluated our framework across 9 tasks, including 8 ICL benchmarks (e.g., SST-2, FinancialPhrasebank, AG News) and open-ended question answering (SQuAD v2.0). The SQuAD dataset is particularly challenging as it contains both helpful context (answerable questions) and adversarial context (unanswerable questions). We tested several models, including Llama-2-7B, Llama-3-8B, and T5-Large.
Key Results
- Guaranteed Safety: Across all tasks and models, the framework successfully bounded the risk of performance degradation within the user-specified tolerance $\epsilon$.
- Efficiency Gains: By exiting early on clear, helpful context, the system achieved massive speedups. On ICL tasks, we evaluated 53% fewer layers on average compared to baseline risk control methods. On SQuAD v2.0, the reduction in layers reached up to 81.8%.
- Intelligent Fallback: The system demonstrated a high degree of context-awareness. In SQuAD, it triggered the zero-shot fallback 3.3x more frequently for unanswerable/misleading questions than for answerable ones, effectively filtering out harmful inputs.
Conclusion
Our work demonstrates that early-exiting is not merely a tool for computational efficiency but also a powerful mechanism for model safety. By anchoring LLM behavior to a zero-shot baseline and applying principled risk control, we can create systems that are robust to corrupted contexts while remaining highly efficient when given helpful information. Future work will explore extending these guarantees to specific worst-case prompts and handling mixed-quality contexts within a single prompt.
Summary updated