Beyond Document Grounding: Span-Level Hallucination Detection over Code, Tool Output, and Documents
This paper introduces a unified benchmark for span-level hallucination detection across diverse structured inputs like code and tool outputs, demonstrating that a fine-tuned Qwen3.5-2B model significantly outperforms existing detectors and zero-shot judges on these complex domains while maintaining competitiveness on natural-language RAG benchmarks.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are hiring a very smart, fast-talking assistant to write a report for you. You give them a stack of reference books (the "context") and a specific question. They quickly type up an answer.
The problem? Sometimes, even the smartest assistants get a little creative. They might invent a fact, mix up a number, or quote a page that doesn't exist in your books. This is called a hallucination.
For a long time, researchers have built "fact-checkers" to catch these mistakes, but they mostly only worked when the assistant was writing about normal topics like history or science using plain text.
This paper introduces a new, much tougher fact-checker designed for the modern world, where assistants are also writing computer code, summarizing software tool logs, and reading structured documents like tables and manuals.
Here is a breakdown of what they did, using some everyday analogies:
1. The Problem: The "Code" and "Log" Blind Spot
Imagine your assistant is a mechanic.
- Old Fact-Checkers: Great at checking if the mechanic said, "The car is red" when the car is actually blue.
- The New Reality: The mechanic is now writing a complex repair manual (code) or reading a digital diagnostic screen (tool output). If the mechanic writes a single wrong command like
turn_off_engineinstead ofturn_on_engine, the whole car might break. Or if they list a part number that doesn't exist, the order fails. - The Gap: Existing fact-checkers were like a human reading a novel; they didn't know how to spot a single wrong line in a computer program or a specific error in a software log. They couldn't tell the difference between a real technical term and a made-up one.
2. The Solution: A "Spot-the-Difference" Game
The authors built a massive new training ground (a benchmark) to teach computers how to be these specialized fact-checkers.
- How they made the data: They started with perfect, correct answers (like a perfect repair manual). Then, they used a "hallucination injector" (think of it as a mischievous editor) to sneak in tiny, localized lies.
- Example: They changed a real function name
set_deviceto a fake oneset_active_device. - They didn't just say "This answer is wrong." They marked the exact characters where the lie happened.
- Example: They changed a real function name
- The Variety: They created over 74,000 examples covering:
- Code: Real GitHub software fixes.
- Tool Output: Logs from software tools (like error messages or search results).
- Structured Docs: Research papers, README files, and Wikipedia pages with tables and lists.
- Normal Text: Standard questions and answers (to make sure they didn't forget how to check normal text).
3. The New Detective: "LettuceDetect"
They trained a new AI model (a 2-billion parameter version of a model called Qwen) to act as the detective.
- The Job: The detective looks at the Request, the Reference Books, and the Assistant's Answer. It must point a finger at the exact lie and say, "This specific word is made up," or "This number is wrong."
- The Results:
- On Code and Tools: The new detective is a superhero. It caught 60% of the lies in code and tool logs.
- The Competition: The old "off-the-shelf" fact-checkers (like LettuceDetect-large) and even giant, smart AI judges (Zero-shot LLMs) only caught about 17% to 22% of the lies in code. They were essentially blind to technical errors.
- On Normal Text: The new detective is still very good at checking normal text (scoring similarly to the best existing systems), proving it didn't lose its general knowledge while learning to read code.
4. Why "Span-Level" Matters
The paper emphasizes that they don't just say "Reject this answer." They do Span-Level Detection.
- Analogy: Imagine a student writes a 10-page essay. One sentence is a lie.
- Old Way: "Fail the whole essay." (Too harsh, the other 9 pages might be perfect).
- New Way: "Highlight the one sentence that is a lie." (Precise and helpful).
- In code, this is critical. If a program has 100 lines and only one line is wrong, you don't want to throw away the whole program; you just want to fix that one line.
Summary
This paper presents a new, unified "truth detector" that can handle the messy, technical reality of modern AI assistants. It moves beyond just checking simple text to spotting tiny, dangerous errors in code, software logs, and structured documents.
Their new model, LettuceDetect-Qwen-2B, is significantly better at finding these technical lies than previous tools, especially when the assistant is writing code or reading software logs, while still remaining a top-tier fact-checker for normal language. They have released all their data and models so others can use this "spot-the-difference" game to build better, more reliable AI systems.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.