TL;DR
Instead of fixing Large Language Model (LLM) hallucinations after they happen, QueryBandits introduces a proactive approach by dynamically rewriting user queries before they reach the model. By framing query optimization as a contextual bandit problem based on 17 distinct linguistic features, the framework successfully steers LLMs away from hallucinatory pathways, achieving an 87.5% win rate over a no-rewrite baseline without requiring any model retraining or gradient updates.
What Problem Does This Paper Address?
Large Language Models are notoriously sensitive to how a prompt is phrased; a minor lexical tweak can mean the difference between a perfectly accurate response and a confident hallucination. Despite this, most hallucination mitigation techniques operate post-hoc—filtering, verifying, or correcting outputs after they have already been generated.
While some researchers have attempted to rewrite queries beforehand, current approaches rely on static, "one-size-fits-all" prompting strategies (e.g., always instructing the model to "paraphrase" or "expand" the query). The authors demonstrate that these static strategies are fundamentally flawed: a rewrite that helps one type of query can actually trigger severe hallucinations in another. The challenge lies in dynamically tailoring the rewriting strategy to the unique semantic and linguistic fingerprint of each incoming query.
Methods
The authors introduce QueryBandits, an online decision-making framework that treats query rewriting as a contextual multi-armed bandit problem.
The system operates via a clear sequential pipeline:
- Context Extraction: For every incoming query, an LLM extracts a 17-dimensional binary feature vector representing key structural, lexical, stylistic, and semantic attributes (e.g., presence of negation, ambiguity, rare words, or domain specialization).
- Arm Selection: Based on this context, the bandit selects one of five rewriting "arms" (strategies):
- Paraphrasing: Introduces lexical diversity while preserving core meaning.
- Simplification: Eliminates nested clauses and complex syntax.
- Disambiguation: Resolves vague pronouns or temporal expressions.
- Expansion: Elaborates on named entities and contextual cues.
- Clarification of Terms: Defines specialized jargon or rare terminology.
- Reward Evaluation: The rewritten query is sent to the target LLM. The quality of the output is evaluated using a robust, multi-faceted reward model ($r_t$) optimized via Pareto frontier analysis: $$r_t = 0.6 \cdot s_{\text{llm}} + 0.3 \cdot s_{\text{fuzz}} + 0.1 \cdot s_{\text{bleu}}$$ Where $s_{\text{llm}}$ is a GPT-4o-based factual consistency judge, $s_{\text{fuzz}}$ measures token-set similarity, and $s_{\text{bleu}}$ ensures lexical fidelity.
The authors evaluated several linear contextual bandit algorithms, including LinUCB, FTRL, and Thompson Sampling, alongside non-contextual baselines.
Datasets
The framework was rigorously evaluated across 13 diverse QA benchmarks spanning general knowledge, science, mathematics, and multi-hop reasoning:
- SQuADv2, TruthfulQA, SciQ, MMLU, PIQA, BoolQ, OpenBookQA, MathQA, ARC-Easy, ARC-Challenge, WikiQA, HotpotQA, and TriviaQA.
To ensure a robust evaluation and prevent the bandits from exploiting simple prompt memorization, the authors generated 1,050 lexically perturbed but semantically invariant queries per dataset.
Key Insights and Ideas
- There is No "One-Size-Fits-All" Rewrite: The optimal rewriting strategy depends heavily on the query's linguistic properties. For example, if a query features Domain Specialization, the Expand arm is highly effective because it injects critical context. However, applying Simplify to the same query risks stripping away essential technical signals, triggering a hallucination.
- Static Prompting Can Worsen Hallucinations: Blindly applying a single rewriting strategy across all queries (a common practice in current literature) often yields a higher cumulative regret than doing nothing at all.
- The Benchmark Memorization Trap: When evaluated on raw, unperturbed benchmark datasets, the contextual bandits converged almost exclusively to the No-Rewrite arm. This empirically exposes the tendency of modern LLMs to memorize exact benchmark phrasings rather than deeply understanding their underlying logic. Introducing surface-form novelty via lexical perturbations was essential to force the models to rely on semantic structure.
Key Results
- High Win Rate: The top-performing contextual bandit (QueryBandits-Thompson Sampling) achieved an 87.5% win rate over the no-rewrite baseline.
- Outperforming Static Heuristics: The framework decisively beat standard zero-shot static prompting strategies, outperforming "paraphrase" by 42.6% and "expand" by 60.3%.
- Rapid Convergence: Contextual models successfully leveraged the 17-dimensional linguistic features to hone in on optimal rewrites quickly, accruing an order-of-magnitude less cumulative regret than non-contextual variants or static baselines.
Limitations and Future Work
While highly effective, the authors note a few limitations in the current framework:
- Feature Independence Assumption: The current model treats all 17 linguistic features as independent variables, ignoring potential higher-order interactions where combinations of features might compound hallucination risks.
- Association vs. Causality: The learned regression weights indicate strong associations between specific features and rewrite success, but they do not strictly prove a causal mechanism within the LLM's internal representations.
- Judge Bias: The reward function partially relies on an LLM-as-a-judge ($s_{\text{llm}}$), which may introduce inherent model biases into the training loop.
Future research directions include exploring causal inference techniques to better map feature-arm interactions and capturing pairwise polynomial feature relationships within incoming queries.
Summary updated