Generative AI for legacy code: reverse engineering, documentation and business-rule extraction

- Generative AI is best at explaining legacy code, not converting it. Gartner analysts see clear value in using it to explain technical debt, but limited value in automated translation.
- The gains are measurable. In one peer-reviewed study on 3+ million lines of COBOL, AI cut documentation effort by about 70% and matched expert-written rules 93% of the time.
- Generative AI pays off most when knowledge is at risk: missing or outdated documentation, experts close to retirement, an upcoming migration, logic with regulatory or financial weight, or software inherited through a merger or vendor handover.
- The best approach combines three things: static analysis to map the code precisely, LLMs to explain it in business-readable terms, and domain experts to validate every high-risk rule before anyone relies on it.
Your most important software still runs your business operations, but it’s written in COBOL, PL/I, VB6 or another legacy technology, the original developers have moved on, and the documentation is long out of date.
All of this points to the same problem: nobody fully understands the code anymore, and without that understanding, modernization stalls before it begins. That’s exactly where generative AI can make the biggest difference.
Used well, it turns opaque programs into documentation, dependency maps and business rules your team can verify. With a clearer understanding of the system, teams can modernize faster and make decisions based on evidence rather than guesswork.
What it means to apply generative AI to legacy code
Generative AI for legacy code is the use of large language models (LLMs) to reverse engineer existing software and explain what it does. The model reads the code and produces documentation, architecture and dependency maps, and a list of the business rules the code enforces. Your team then checks these outputs against the source.
Why understanding matters more than conversion
The focus on code understanding sets the approach apart from much of the vendor marketing around AI and legacy code, which usually centers on conversion: COBOL to Java, VB6 to .NET. However, automated conversion is where the technology is least reliable. The new code must match the old system’s behavior exactly, and AI can’t guarantee that on its own.
Industry analysts reach a similar conclusion. In a report on mainframe exit projects, Gartner saw clear value in using generative AI to find and explain technical debt, but warned that it falls well short when it comes to automatically translating and moving legacy code to new platforms.
What exactly does generative AI produce?
The output of generative AI in legacy modernization projects falls into three groups, each answering a different question: how the system is built, what each part of it does, and which business decisions it encodes.
- Architecture and dependency maps — call graphs, data flows, module dependencies, batch-job sequences and the architectural patterns the system follows, recovered from source rather than memory. Good dependency mapping also flags likely dead code and hidden integrations.
- AI code documentation — plain-English summaries of programs, functions, the data model and interfaces, from an executive overview down to engineer-level notes.
- Business rules — a catalog of the decisions the software makes (eligibility checks, pricing formulas, validation thresholds), each linked to the code that implements it.
Why grounding matters when you use generative AI
The outputs received from generative AI are only useful if your team can trust them, and that depends on what the model works from.
Paste raw COBOL into a chat window and you’ll get fluent summaries that may be wrong. The model reads the code as plain text and infers how it works: which programs call which, how data moves between them, which conditions trigger which actions. Usually its guesses are plausible. Sometimes they aren’t, and the output gives no hint which is which.
The solution is grounding: giving the model verified facts about the code instead of letting it infer them. In practice, engineering teams use conventional, deterministic tools to parse the source and break it down into abstract syntax trees (ASTs) and control-flow and data-flow graphs, an exact map of how the code is structured. The LLM then explains that map rather than guessing from raw text, so its claims can be checked against the code.
When to use AI for legacy systems: five scenarios
Most legacy codebases can benefit from generative AI. But in a few scenarios, the payoff is especially clear.
1. The documentation is missing, outdated or wrong
When documentation is missing, outdated or wrong, every change starts with guesswork about what the code actually does. Generative AI can draft documentation across the whole codebase, at a scale manual efforts rarely reach. And because it works from the code itself, it describes what the system does today rather than what someone wrote down years ago.
2. Your subject-matter experts are close to retirement
In many legacy systems, critical knowledge lives only in the heads of a few long-serving experts, and it leaves when they do. Generative AI helps capture it in time: instead of explaining the system from memory, experts review and correct AI-generated documentation and rule catalogs. Correcting a draft is far faster than writing from scratch, so you record more of their knowledge before they go.
3. You’re planning a migration and don’t know what you’d be moving
Choosing between rehosting, refactoring or rebuilding requires an inventory of modules, dependencies, likely dead code and embedded rules. Without it, the plan rests on guesses. Generative AI, grounded in static analysis, builds that inventory much faster than a manual review. Our overview of legacy system modernization approaches explains the options and when each one fits.
4. The logic carries regulatory or financial weight
In banking, insurance, healthcare and government, a calculation that changes during a migration can mean incorrect payments, misstated reports or a compliance breach. Business-rule catalogs extracted with generative AI, each linked to the code that implements it, give your team a documented baseline to test the new system against and give auditors evidence of how each rule was carried over.
5. You’ve acquired or inherited someone else’s software
After a merger, or when a vendor or outsourcing partner hands over a system, your team can end up owning code it has never read. Generative AI speeds up discovery, so you learn what you now own, how it works and where the risks are much sooner than through a manual code review.
Probably not a fit: small, well-tested applications with up-to-date documentation and an active team that knows the code. There’s little missing knowledge to recover, so the effort rarely pays off.
Benefits of AI-driven legacy application modernization
1. Much faster discovery
Understanding a legacy system has traditionally meant engineers reading unfamiliar code line by line, often in languages few of them know well. Generative AI can speed up this work by drafting documentation, identifying business rules and helping map dependencies. Engineers just review and verify AI-generated findings, which significantly cuts the time needed to understand the existing system.
2. Less documentation effort
Writing documentation by hand is slow, and for large codebases, it often remains incomplete. Generative AI can write the first drafts, so specialists only need to read them through and refine them. A peer-reviewed industry paper presented at ACL tested this on more than 3 million lines of COBOL in the financial sector and reported about 70% less documentation effort and more than three times faster analysis than manual methods.
3. Business rules you can trace back to source
In the same ACL study, business rules extracted by generative AI matched rules written by experts about 93% of the time. The remaining errors have to be caught by people, and traceability makes that practical: each extracted rule is linked to the exact code that implements it. Reviewers can open the code behind any rule and confirm or correct it directly.
4. Less dependence on a few key people
When only one or two engineers understand a system, every change, incident and release waits on them, and a single resignation can stall the work. Generative AI turns what lives in their heads into shared documentation, dependency maps and rule catalogs that anyone on the team can use.
5. Better modernization decisions
If you simply translate legacy code into a new language, its problems move with it to the new system, and the issues that triggered modernization in the first place remain unsolved. Using generative AI to understand the code first changes that. It shows which parts are still essential and which are duplicated or likely unused, and it surfaces the rules so your team can spot those that no longer reflect how the business works. That lets you keep what matters, retire what doesn’t, and modernize with a well-defined scope.
How AI-assisted reverse engineering compares with the alternatives
Generative AI isn’t the only way to understand a legacy system. Teams have long relied on other methods, and each still has its place. The comparison below shows where generative AI adds value.
| Approach | What it means | Where it works best | Trade-offs |
| Manual reverse engineering | Experienced engineers and domain experts read code, trace workflows, and reconstruct business logic. | Investigating ambiguous business logic, validating undocumented behavior, and resolving critical edge cases that require domain expertise. | Time-consuming and expensive for large systems. Depends heavily on access to experienced specialists. |
| Traditional static analysis and rule mining | Automated tools analyze source code to identify dependencies, control flows, data flows, and patterns that may represent business rules. | Precisely mapping code dependencies, call graphs, control flow, and data flows using predefined analysis rules. | Findings can be difficult for business users to interpret. Extracting meaningful business rules still requires expert analysis. |
| LLMs with static analysis and human validation | LLMs interpret legacy code and analysis results to draft documentation, explain dependencies, and identify business rules for expert review. | Accelerating discovery and producing business-readable documentation across complex, poorly documented systems. | AI can sometimes misinterpret logic or miss dependencies. Requires reliable source context, expert validation, and upfront setup. |
Who’s involved: the team behind AI code documentation
Generative AI doesn’t remove people from reverse engineering; it changes what they spend their time on. Instead of reading code line by line and writing documentation from scratch, engineers set up the analysis, guide the model and verify what it produces. The team is usually small, and most of its roles already exist in any modernization project.
- Solution architect — defines the scope, chooses the analysis tools and target architecture, decides how parsing and the LLM work together, and owns technical risk.
- Senior engineers — set up the parsing pipeline, prompts and output formats, check generated documentation against the source, flag dead or duplicated logic, and turn rule catalogs into requirements the business can approve.
- QA / test automation engineer — writes characterization tests that record what the old system actually does, so every later change can be checked against it.
- DevOps engineer — sets up the secure environments where the code is analyzed, connects the tooling to source repositories, and keeps documentation up to date as the code changes.
- Security lead — decides where source code and data may be processed and which models are allowed.
On smaller projects, one person often covers two roles. The team also relies on the client’s legacy domain experts, the people who know the system’s undocumented behavior and confirm the extracted rules. Their review and testing are the two things never to cut. Projects often run short on both, and our step-by-step modernization roadmap explains why each one matters.
How to extract business rules from code with AI: a phased guide
Reliable results don’t come from pointing an AI model at a codebase and asking it to explain everything. They come from a structured process that limits what the model has to guess, puts people in charge of what gets approved, and turns the results into something the modernization team can use.
Phase 1: Scope and secure
- Inventory the system: languages, lines of code, schedulers, databases and integrations. Mark what is critical and what is likely unused.
- Pick one high-value slice: pilots that try to cover everything tend to stall (it can be, for example, such as claims adjudication or interest calculation).
- Decide where the source code may be processed: a commercial API under an enterprise agreement, private cloud or on-premises. Check the provider’s data terms, such as whether your code is retained or used for training, and record the decision for auditors.
- Define the output: a rule template with ID, business description, inputs, conditions, outcome, source reference, confidence level and review status.
Phase 2: Ground the model in your source
- Parse the code with deterministic tools and map dependencies: ASTs, control-flow and data-flow graphs, and links to copybooks and database schemas. No LLM yet.
- Build a knowledge graph (or a similar structured index): it links programs, data elements, jobs and screens, so the model can see how the parts of the system connect.
- Set up retrieval (RAG): for each request, the system finds the relevant code and context and passes only that to the model, since it can’t process the whole codebase at once.
Phase 3: Generate and validate
- Generate in layers: module summaries first, then explanations of how data flows through the system, then candidate rules. Each layer gives the model context for the next.
- Validate with people: domain experts review every high-risk rule and a sample of the rest. Track how many rules they accept or correct, and if accuracy drops, improve the prompts or the context the model receives.
- Back rules with tests: turn approved rules into tests and run them against the old system to confirm it really behaves that way. These tests then become the baseline for checking the new system.
Phase 4: Put the knowledge to work
- Feed the backlog: approved rules become requirements for refactoring or rebuilding.
- Publish documentation where people already look: the wiki, the repository, or an internal AI assistant your team can ask questions. Regenerate it as the code changes so it doesn’t go out of date again.
- Expand slice by slice across the wider modernization program: later slices usually go faster, since the pipeline, prompts and templates are already in place.
From documentation to delivery: where coding agents fit
Once the extracted knowledge has been verified, AI coding tools become safer and more useful. This is where reverse engineering turns into code modernization.
- Context-aware coding assistants. AI assistants such as GitHub Copilot can give better suggestions when extracted rules and documentation sit in the repository beside the source.
- Coding agents for repetitive changes. Agents handle mechanical work spread across many files: renaming fields, replacing deprecated APIs and updating code to new framework versions. Larger structural changes, such as splitting modules into services, still need an architect’s design, with agents assisting in the implementation. Each change arrives as a pull request for human review.
- Impact analysis before code changes. Before a change is made, the dependency graph shows which jobs, screens and reports it touches.
- Regression safety nets. Characterization tests run in the CI pipeline on every pull request, so if generated code alters the old system’s behavior, the build fails before the change is merged.
The principle holds: AI-powered tools propose, engineers decide what to refactor and merge. The result is faster modernization with fewer surprises, and a team that spends less time deciphering old code and more time improving it.
What does AI-assisted reverse engineering cost?
There’s no single price, because the cost depends less on the AI itself than on the system you’re analyzing and the team you work with. These are the factors that move the number most:
- Codebase size and technology. Cost grows with the amount of code, but the language matters just as much. Mainstream languages such as Java are far cheaper to analyze than COBOL with IDMS, assembler or a proprietary 4GL, where parsers are less mature and AI models have seen far less code to learn from.
- Existing documentation and tests. Even partial documentation and tests reduce the effort, because they give the model something to check against and reviewers a head start.
- Validation depth. Often the largest line item. Rules with regulatory or financial impact need near-complete review by domain experts; less critical internal logic can rely on sampling.
- Hosting. Using a commercial model through an API costs relatively little per run. Private or on-premises models add the cost of the infrastructure and the work to run and maintain them.
- Team location. Central and Eastern European teams typically cost significantly less than US or Western European ones at comparable seniority, which is why many companies use nearshore partners for labor-heavy modernization work.
In general, AI processing itself is rarely the main expense. Most of the budget goes to people: the engineers who set up the analysis and the experts who review what it produces. For a wider breakdown, see how much legacy system modernization costs.
Best practices for long-term success
Keep humans accountable for every rule
Developers already treat AI output with caution. In Stack Overflow’s latest Developer Survey, about half of developers said they rely on AI results only if they can check them easily, and just 6.6% would rely on it for important decisions. Business rules that control payments, eligibility or compliance are exactly those decisions, so verification has to be built into the process.
Give every rule a named owner who approves it, and keep a record of who approved what and when. The same applies to any code generated from those rules: scan it against your secure coding standards before it’s merged, so no new vulnerabilities slip in.
Treat documentation as a living asset
Documentation starts going out of date as soon as the code changes again. To keep it current, build updates into your CI/CD pipeline (the automated process that tests and deploys code changes): whenever a program changes, regenerate its summaries and flag the affected business rules for review. Understanding the system then becomes an ongoing habit rather than a one-off project.
Change what matters, not everything
Use what you’ve learned about the system to set priorities: retire code that’s no longer used, consolidate duplicated logic, and invest where the business needs change. A full rebuild is often unnecessary. In our RPA platform modernization project, for example, we added an extension-based architecture around the existing system instead of rebuilding it from scratch.
The same targeted approach works in healthcare software modernization, where regulations make large rewrites especially risky, and in .NET migration of older Microsoft applications.
Conclusion
The hardest part of modernization has always been understanding the software before changing it, and that is where generative AI now offers some of its most reliable value. Grounded in real code analysis and checked by people who know the business, it turns years of undocumented logic into knowledge your teams can audit and build on. Producing output is easy; making it trustworthy is the real work.
To see what this reveals in your own estate, contact Abto Software and we’ll start with a focused, fixed-scope assessment.
FAQ
For a single, self-contained program, it often does a reasonable job, though the result still needs checking. Across thousands of interconnected programs and batch jobs, it can’t. The chatbot only sees the code it’s given, so it misses how data moves between programs and fills the gaps with confident guesses. Reliable results require parsing the whole codebase first, so the model works from a complete map of the system.
It can be, if you choose how the model is deployed deliberately. There are three main options, each reducing exposure at a different cost: a commercial model under an enterprise agreement that excludes your data from training and limits how long it’s retained, a model hosted in your own cloud account, or a model running entirely on your own servers.
Whichever you choose, remove passwords, keys and personal data from the code first, since legacy code often contains them, and document where the code goes and who can access it, so you can show auditors.
Results vary with the codebase, the tools and how well the model is grounded. In one peer-reviewed industry study on a large COBOL codebase, extracted rules agreed with expert-written rules about 93% of the time. That’s high enough to speed up the work considerably, but too low to skip expert review. The only reliable figure for your system is the one you measure yourself, so track accuracy during the pilot.
First, check whether it really is lost. Source code often survives in old backups, retired servers, version control archives, or a software escrow agreement with the original vendor. On mainframes, compiler listings sometimes still exist even when the source files don’t.
If it’s truly gone, you can still recover much of the system’s logic. Applications built on platforms like .NET or Java can be decompiled into fairly readable code. Natively compiled programs, such as COBOL or assembler running directly on the machine, are much harder to reconstruct, and the result is far less readable. Generative AI can help explain recovered code, but accuracy is lower than with the original source, so expert review becomes even more important.
You can also learn from how the system behaves: its database structure, input and output files, logs and screens. Recording what the system does with real inputs gives you characterization tests and a picture of its business rules, even without any code.
Not in this kind of work. AI agents take over much of the manual reading and repetitive changes, but someone still has to judge whether the output is correct, decide what changes to make and approve what gets merged. That requires knowing both the system and the business, so experienced legacy developers become more valuable, not less. Their work shifts from deciphering code to reviewing, verifying and guiding the AI.
A well-scoped pilot on one business area typically produces reviewable documentation and a first business-rule catalog within a few weeks, depending on the size of the code and how quickly experts can review it. Later stages usually move faster, because the parsing, analysis setup and templates are already in place.



