Edit Footprints: Detecting and Repairing RAG Hallucinations by Watching What a Rewriter Changes

Retrieval-augmented generation (RAG) means having a language model answer from documents fetched at query time, and it is now the default way to make models factual. It still fails in a characteristic way. The model adds claims that appear nowhere in the retrieved documents, and these unsupported additions outnumber outright contradictions (RAGTruth). Catching such claims is hard when the generator is a commercial API that exposes only text. Asking a strong model to point at the bad spans works poorly: prompted GPT-4 reaches only 28.3% span-level F1 on RAGTruth. A separate literature on detecting machine-written text found a more useful behavioral signal. When you ask a model to rewrite text that matches its own habits, it changes very little. When you ask it to rewrite text that does not, it changes a lot (Raidar).

We propose to turn that signal toward faithfulness. Ask a rewriter to make a RAG answer faithful to its documents while changing as little as possible. The spans it alters are the hallucinations, and its output is the repaired answer. To remove edits that are merely stylistic, compare against a second rewrite made without the documents. Then use supervised fine-tuning followed by reinforcement learning to train a small model to be exactly this minimal, faithful editor. The training uses only an entailment reward and an edit-cost penalty, with no span labels, so one cheap call both locates and fixes unsupported claims.

Core Claim

Models are poor at labeling their own hallucinations. ChatGPT is near chance when judging summaries for hallucination in HaluEval. We conjecture that the same models are much better at fixing unsupported claims when told to stay close to the documents, and that the location of their edits is a sharper detector than their verdicts. Our claim has two parts.

The first part is a black-box score that needs no training. For a response $y$ with retrieved documents $D$, let $d_D(s)$ be the fraction of tokens in span $s$ that a rewriter changes when asked to make $y$ faithful to $D$ with minimal edits. Let $d_\varnothing(s)$ be the same fraction when the rewriter is only asked to proofread $y$ and never sees $D$. The span's unfaithfulness score is

$$u(s) = d_D(s) - d_\varnothing(s).$$

The subtraction cancels the rewriter's general appetite for restyling text. That appetite is exactly what Raidar measures, and Raidar notes it drifts as generators change.

The second part is that reinforcement learning can make the edits sparse and well placed. We train the editor with the reward

$$R(y') = \mathrm{NLI}(D \Rightarrow y') - \lambda \, \mathrm{edit}(y, y').$$

Here $y'$ is the edited response. $\mathrm{NLI}(D \Rightarrow y')$ is the mean probability that each sentence of $y'$ is entailed by the documents, as judged by an off-the-shelf natural-language-inference (entailment) model. $\mathrm{edit}(y, y')$ is the normalized token edit distance, and $\lambda$ trades faithfulness against change.

The reward is sentence-level and label-free. We hypothesize that span-level localization emerges from the pressure to edit minimally. That hypothesis is the claim the experiments must test.

Relation to Prior Work

Three kinds of prior work matter here: work that motivates the proposal, work that constrains it, and work whose methods we reuse.

Raidar supplies the method. It prompts an LLM to rewrite text and uses edit distance to separate human from machine authorship. It never asks whether hallucinated machine text rewrites differently from grounded machine text, and it never conditions the rewrite on evidence. Both of those are the core of our proposal. SimLLM applies regeneration similarity at the sentence level, and the code-rewriting detector applies it to source code. Both stay with the authorship question.

Hallucination detectors constrain the design. SelfCheckGPT measures whether $N$ resampled answers agree with each other. That checks consistency with the model's own memory, not with the documents. A baseless claim the model reliably believes will pass. LUMINA measures how much the model uses its context versus its internal knowledge, and exceeds 0.9 AUROC on HalluRAG, but it needs logits and intermediate layers. RaDIO triggers retrieval from a classifier over hidden embeddings. We keep the question LUMINA asks, whether the claim came from the context, and answer it from text alone.

Post-training work supplies the training recipe. RAGTruth trains a Llama-2-13B critic with supervised fine-tuning (SFT, imitation of labeled examples) on span labels and filters candidate answers with it. HCPD trains a judge with Group Relative Policy Optimization (GRPO, a reinforcement learning method that scores groups of samples relative to each other). That judge answers from its own knowledge and has no access to documents. TruthRL and behaviorally calibrated RL reshape generator rewards to discourage guessing. The two-stage math recipe shows SFT setting capability and RL trimming excess output. We transplant its length penalty into an edit penalty, and we train a separate editor rather than the generator. That choice lets the method audit closed APIs.

Research Program

Step 1: test whether the signal exists, with no training. On RAGTruth's span-annotated responses, we compute $u(s)$ using an open instruction model as the rewriter. We align edits to spans with token-level diffs. We report how $d_D$, $d_\varnothing$, and $u$ separate annotated baseless and conflicting spans from clean ones, broken down by task, by generator, and by position in the response. Position matters because RAGTruth reports that hallucinations cluster toward the end of long answers.

Step 2: train the editor in two stages. The SFT cold start teaches the output format and the habit of minimal edits. Its training pairs are synthetic: we take faithful responses, inject unsupported sentences or entity swaps, and supervise the model to restore the original. This uses no human span labels. GRPO then optimizes $R$ on unlabeled RAG responses drawn from several generators.

We will sweep $\lambda$. Too small a value lets the editor rewrite everything into a safe paraphrase. Too large a value makes it edit nothing. We report the frontier between the two. We will also guard against reward hacking, such as deleting whole answers, by adding a floor on answer coverage. Any such pathology we observe will be reported.

Step 3: deploy. At inference the trained editor runs once with the documents. The no-context rewrite becomes optional and is ablated. Its edits give span scores, and its output replaces the response.

Baselines

The naive reference is no detector and no repair: the raw generator output, scored for hallucination rate. For detection, the floor is a span-agnostic predictor at the RAGTruth base rate.

The strongest detection competitor is RAGTruth's own fine-tuned Llama-2-13B critic. The paper reports 78.7% response-level F1 and 52.7% span-level F1, against 63.4% and 28.3% for prompted GPT-4. We retrain it on the same RAGTruth training split, the same base-model size as our editor, and a matched GPU-hour budget. Prompted GPT-4 also serves as the frontier-judge baseline.

Beating the supervised critic in its own setting, trained on in-distribution labels and tested on generators it has seen, is not required for our claim. Two results would count as winning. The first is matching it within a few F1 points on seen generators with zero span labels. The second is exceeding it on held-out generators and tasks.

For mitigation, the strongest competitor is the same critic used for rejection filtering. RAGTruth reports that this reduced Llama-2-7B's hallucination rate by 63.2%. On CRAG, TruthRL cuts hallucination from 43.5% to 19.4%, but it does so by retraining the generator. We report it as a reference point, not a like-for-like comparison.

On HalluRAG, LUMINA's 0.9 AUROC is a white-box upper reference. Being within reach of it with text-only access is the goal. We also run SelfCheckGPT with the same number of model calls as our method.

Three ablations isolate the ingredients. Dropping the no-context rewrite tests the differential. Using the SFT-only editor tests whether RL is needed. Using a prompted untrained rewriter at the same size tests whether training matters at all.

Why not just…?

Why not just fine-tune a span detector on RAGTruth labels? This is the real threat. In distribution it may well win, since it reaches 52.7% span F1 with direct supervision. Our bet rests on three advantages it lacks. Our method needs no human span labels. Its signal is defined by the documents rather than by the training generators' error styles, so it should transfer better. It produces a corrected answer instead of a rejection.

The held-out-generator split settles this. We train both methods on Llama-2 and Mistral responses and test on GPT-3.5 and GPT-4 responses. If the supervised critic also wins there, our contribution shrinks to label-free repair, and we will say so.

Why not just check each sentence against the documents with an NLI model? That model is literally inside our reward, so a reviewer will suspect we merely distill it. Sentence-level NLI cannot say which words are unsupported, and it struggles with the subtle conflicts RAGTruth annotates. We compare NLI flagging directly at span level and response level. If NLI matches the editor's span F1, the RL stage adds only correction, not detection.

Why not just prompt a strong model to rewrite, or to judge, with no training? Prompted judging is documented to be weak: 28.3% span F1 for GPT-4 on RAGTruth and 58.53% accuracy for ChatGPT on HaluEval summarization. Prompted rewriting is the training-free version of our score and appears in our ablations. If it already matches the trained editor, the paper becomes a training-free method. That would still be a useful result, but a smaller one.

Why not just use SelfCheckGPT? Resampling tests whether the model agrees with itself, not with the documents. Confident baseless claims will look consistent, and the method costs many calls. The call-matched comparison on RAGTruth and HalluRAG, split by baseless versus conflicting spans, will show where it fails.

Proposed Experiments

Decisive check 1: does the signal exist? Before any training, $u(s)$ must separate hallucinated from clean spans on RAGTruth clearly better than $d_D$ alone. If it does not, the differential idea is wrong. We also expect $u$ to stay informative toward the ends of long answers, where hallucinations concentrate.

Decisive check 2: detection under shift. We report span F1 and response F1 on RAGTruth with the held-out-generator split described above, and AUROC on HalluRAG, against all baselines.

Decisive check 3: repair. After editing, we measure the hallucination rate on RAGTruth generators and CRAG, using the same LLM judge for all methods. We compare against critic-based rejection, and we report alongside it how much of the original answer content survives the edit. A method that removes hallucinations by deleting everything has not succeeded.

Cost. We record wall-clock time and model calls per response against SelfCheckGPT and HCPD. HCPD reports about 1.1 seconds with five samples.

The proposal succeeds if three conditions hold together. The label-free editor approaches the supervised critic on seen generators, beats it on unseen ones, and lowers hallucination rates while preserving most of each answer.