Hallucination Inspector: A Fact-Checking Judge for API Migration
This paper introduces Hallucination Inspector, a static analysis tool that detects "scaffolding hallucinations" in LLM-generated API migration code by verifying extracted symbols against API documentation, thereby overcoming the limitations of standard metrics and probabilistic judges.
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 talented, but slightly overconfident, apprentice chef to rewrite an old family recipe for a modern kitchen. The old recipe calls for a specific, rare spice that is no longer sold. The chef knows the concept of the new spice they should use, but when it comes time to actually cook the dish, they start making things up.
They might say, "I'll use the new spice, but I need to mix it with a 'Magic Whisk' that doesn't exist," or "I'll stir it with a 'Silver Spoon of Destiny' that was never invented." The dish looks delicious on paper, and the ingredients list is 90% correct, but the moment you try to cook it, the kitchen explodes because those tools are imaginary.
This paper is about a new tool called Hallucination Inspector that acts like a strict, fact-checking head chef to catch these mistakes before the cooking starts.
Here is the breakdown of the problem and the solution, using simple analogies:
1. The Problem: "Scaffolding Hallucination"
When computers (specifically Large Language Models or LLMs) try to update old software code to work with new systems (API migration), they are good at the big picture. They know, "Okay, we aren't using the old MediaPlayer anymore; we need to use the new AudioAttributes."
However, they are terrible at the glue code—the tiny, boring details that hold the structure together.
- The Mistake: The computer invents "Phantom Symbols." These are imaginary imports, fake constants, or methods that look real but don't exist in the official documentation.
- The Analogy: It's like the chef writing, "Add a pinch of Unicorn Dust." The recipe looks perfect, but you can't buy Unicorn Dust. If you try to follow the instructions, the recipe fails.
2. Why Old Tools Failed
The researchers tried to use standard ways to check if the code was good, but they failed miserably:
- The "Similarity Score" (CodeBLEU): This is like a teacher grading an essay by counting how many words match the "perfect" essay. If the chef writes a recipe that is 95% identical to the real one, but includes one fake ingredient ("Unicorn Dust"), the similarity score is still 95%. The tool says, "Great job!" while the dish is actually inedible.
- The "AI Judge" (LLM-as-a-Judge): This is like asking another AI chef to check the first chef's work. But since both chefs are prone to daydreaming, the second chef often agrees with the first one, saying, "Yeah, Unicorn Dust sounds right!" or gets confused and rejects a perfectly good recipe. They are too optimistic or too biased.
3. The Solution: Hallucination Inspector
The authors built a new tool called Hallucination Inspector. Instead of guessing or counting words, this tool acts like a Fact-Checking Librarian with a strict rulebook.
Here is how it works:
- The Rulebook (The Oracle): The tool has a digital copy of the official API documentation. This is the "truth." It knows exactly what tools, ingredients, and methods exist. Nothing else is allowed.
- The Scan (Static Analysis): It takes the code the AI generated and breaks it down into its smallest parts (like a sentence diagram).
- The Two-Step Check:
- Step 1: Atomic Check: Does this specific word (like a constant or a class name) exist in the rulebook? If the code says "Unicorn Dust," the Librarian checks the book, finds nothing, and immediately flags it.
- Step 2: Context Check: Does this tool make sense in this specific situation? For example, maybe "Whisk" exists, but you can only use it on a cake, not on a soup. If the code tries to use a "Whisk" on "Soup," the tool catches that mismatch.
4. The Results
When they tested this on Android app updates:
- Old Metrics: Missed almost all the fake ingredients because the recipes looked so similar to the real ones.
- AI Judges: Got confused and made up their own rules, often approving bad code or rejecting good code.
- Hallucination Inspector: Caught 100% of the fake ingredients (Phantom Symbols) without making false alarms. It was the only tool that said, "Stop! This tool doesn't exist in the official manual."
The Big Takeaway
In the world of software, AI is great at writing the "story" of the code, but it often invents the "facts." You can't just ask the AI to check its own work, and you can't just look at how similar the code looks to the original.
You need a deterministic fact-checker—a tool that doesn't guess, but simply compares every single word against the official manual. The Hallucination Inspector is that tool, ensuring that when AI helps migrate software, it doesn't leave us with recipes full of imaginary ingredients.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.