IBM Patents a Fact-Checker That Catches AI Making Things Up in Code Explanations
AI can explain a pile of old code in seconds, but sometimes it confidently describes things the code never does. IBM's filing adds a fact-checker that tests each sentence against the code itself.

- Publication number
- US 2026/0386829 A1(US20260386829A1)
- USPTO patent title:
- Mitigating Hallucination in Code Summaries
- Applicant
- INTERNATIONAL BUSINESS MACHINES CORPORATION
- Filed · Published
- Jun 3, 2025 · Dec 3, 2026
- Inventors
- Srikanth Govindaraj Tamilselvam, Sameer Pimparkhede, Kishan Maharaj, Prince Kumar
- Status when we published
- Waiting for an examiner
- Document
- 20 claims
- US classification
- 717/120
What IBM's code-summary fact-checker does
A programmer inherits a huge, old codebase that nobody documented. Asking an AI to explain what each piece does sounds like a lifesaver, until the AI confidently describes something the code never does. Chatbots make things up about trivia, and they do it with code too.
IBM's patent application tackles that with a built-in fact-check. The system first reads the code the old-fashioned way, without AI, and builds a list of plain facts: this line assigns a value, that line calls a function, this loop repeats. Then the AI writes its explanation, and each sentence gets compared against that list.
Sentences that match the facts stay. Sentences that contradict the code get thrown out. Sentences that are almost right get corrected, like a mix-up between two variable names. The AI is also pushed toward names that really exist in the program.
generating normalized triplets from source code using static analysis; generating tokens of a summary of the source code using a large language model (LLM); creating a template for an entity in the tokens based on the normalized triplets; and generating additional tokens of the summary using the LLM, constrained by the template.
Translation: The system uses traditional code analysis to build a strict factual outline that forces the AI writer to stay accurate.
How IBM checks each sentence against the code
The method starts with static analysis (examining code without running it) to produce normalized triplets. A triplet is a short three-part record: a relationship plus the two things involved. For the line x = y + z, the record is (assign, x, y+z). A call to print("Hello") becomes (call, print, "Hello").
Three kinds of analysis feed the list:
- Abstract syntax tree (AST) analysis (a map of how the code is structured) handles simple assignments and function calls.
- Semantic analysis adds context such as data types and known values.
- Control-flow graph (CFG) analysis (a map of the paths a program can take) handles conditions and loops.
The filing also describes normalizing the records so different wordings, like "decide" and "deciding," become one consistent term.
The core claim is about generation. The large language model (LLM, the AI that writes the text) begins a summary. When it reaches a named item such as a method or variable, the system builds a template listing only the valid options from the code, and the LLM must finish within it.
The filing also describes pulling triplets out of the AI's own summary and comparing them to the code's triplets. Matches are kept, non-matches are discarded, and partial matches are fixed. In its example, a summary that names y where the code says x is corrected to x.
Why IBM cares about trustworthy code explanations
If you work on software, the worst bug is the one you were told wasn't there. An AI that explains old code incorrectly can send you down the wrong path for hours, and the more fluent the explanation sounds, the easier it is to believe. A checker built into the tool means you read fewer confident mistakes.
The filing is aimed at maintaining large legacy code bases, where nobody remembers why things were written the way they were. Checking the AI against the code itself gives companies a way to use AI documentation tools with less worry about invented details. For everyone else, it is a small example of a wider habit: pairing a chatbot with a rule-based checker that can say no.
IBM's 89th filing we've tracked in our AI safety guardrails watch since May builds on earlier applications like a quiz catching AI contradictions and a pre-delivery output filter.
Source: US 2026/0386829 A1 at the USPTO (PDF). Full patent text and figures are in the official publication.
Get our take in your Top Stories
Liked this breakdown? Add Patentlyze as a preferred source on Google, and our plain-English take shows up more often in your Top Stories the next time IBM patent news breaks.
We read the new patents from Big Tech, carmakers and more and send you the ones worth knowing. Plain English, free, every week.
The drawings · 6 sheets
6 drawing sheets from US 2026/0386829 A1 · click any drawing to enlarge

No comments yet