Home / Insights / Generative AI and LLMs
Generative AI and LLMs
Generative AI for Code Documentation and Knowledge Transfer in Legacy Systems
Legacy systems often run critical operations while the people who understand them move on. Generative AI can draft documentation and answer questions about old code, but only with verification, good context and clear ownership. This guide shows how to make it work.
Key takeaways
- The goal is reduced key-person risk and faster onboarding, not a pile of generated pages. Define which questions new engineers and operators must be able to answer.
- Generative AI is strongest at explaining code it can see: module summaries, call flows, data dictionaries and change histories. It is weakest at business intent, which still has to come from people.
- Treat every generated document as a draft. Verify against code, tests and expert review, and record what has been checked.
- Context engineering matters more than model choice: give the model the right files, schemas, logs and existing documents, because models do not use very long inputs reliably.
- Keep documentation alive by generating and reviewing it in the same pipeline as code changes, and by protecting source code and secrets when using external models.
On this page
- What problem are you actually solving?
- Where does generative AI help, and where does it fall short?
- Which approaches and tools should you consider?
- How do you give the model the right context?
- How do you verify AI-generated documentation?
- What are the security, cost and organisational risks?
- A step-by-step rollout plan
- Frequently asked questions
- Sources and methodology
Every organisation with software older than a decade has a version of this problem: a billing engine, a claims system or an integration layer that works, earns money, and is understood by very few people. Documentation is outdated or missing. The original authors have left or are about to retire. New engineers take months to become productive, and every change feels risky.
Generative AI tools can now read large amounts of code and explain it in plain language, which makes documentation and knowledge transfer far cheaper than it used to be. This article is for CTOs, engineering managers and operations leads who own such systems. As CTO, I want to be clear about where these tools help, where they mislead, and how to put guardrails around them. This is part of our generative AI development work, which includes summarisation with links back to the source, structured extraction, evaluation and guardrails, and configuring providers so data is not used for training where supported, or using self-hosted models.
What problem are you actually solving?
Before choosing tools, define the outcome. Documentation is a means; the ends are usually one or more of these:
- Reducing key-person risk: capturing what one or two experts know before they leave.
- Faster onboarding: new engineers, or a new partner team, making safe changes sooner.
- Safer change: understanding the impact of a change before making it.
- Operational support: on-call staff diagnosing incidents without waking the one person who knows.
- Modernisation planning: knowing what the system does before replacing parts of it.
Modernisation planning is a related but different job, covered in our guide to using AI to reverse-engineer legacy applications. This article focuses on documentation and knowledge transfer for systems you will keep running, at least for now.
Turn outcomes into questions
Write down the questions a competent newcomer must be able to answer, for example: how does an order flow from intake to invoice; which batch jobs run overnight and what happens if one fails; which tables hold customer balances and who writes to them; what rules decide a discount. These questions become the scope of the documentation and, later, the test set for whether it is good enough.
Action: collect 30 to 50 real questions from new joiners, support tickets and incident reviews before generating anything.
Where does generative AI help, and where does it fall short?
Large language models are good at explaining what code does when they can see it. They are much less reliable on why it was written that way, which often lives in people’s heads, old tickets or contracts.
| Task | AI usefulness | Human role |
|---|---|---|
| Module and file summaries | High | Spot-check accuracy |
| Call flows and dependency maps | High with static analysis support | Confirm runtime behaviour |
| Data dictionaries from schemas and code | High | Add business meaning and ownership |
| Explaining obscure languages or idioms (COBOL, old PL/SQL, VB6) | Medium to high | Verify edge cases |
| Business rules extraction | Medium | Confirm with domain experts and tests |
| Design rationale and history | Low without tickets and commit history | Interview experts |
| Operational runbooks | Medium when given logs and incident notes | Rehearse and approve |
There is growing evidence that these tools speed up work on large codebases. Google’s engineers, in an experience report titled How is Google using AI for internal code migrations?, describe evidence that LLMs can significantly reduce the time needed for migrations and lower the barrier to starting them. The same capabilities that help migrate code help explain it, but a migration has compilers and tests as a safety net; documentation often does not, which is why verification matters so much.
The misinformation risk
The OWASP Top 10 for LLM Applications 2025 lists misinformation as a core risk for applications that rely on model output. In documentation, a confident but wrong explanation is worse than no documentation, because engineers trust it and act on it.
Action: label each documentation type as AI-drafted, human-verified or human-authored, and show that status on every page.
Which approaches and tools should you consider?
1. Assistant in the editor
Engineers use a coding assistant to ask questions about the code they have open and to draft comments or docstrings. Low setup cost, but knowledge stays in individual chats unless people write it down.
2. Agentic coding tools over the repository
Agentic tools can explore an entire repository, run searches and commands, and produce structured documents. Anthropic’s Claude Code documentation, for example, describes a tool that reads your codebase, edits files and runs commands, and reads a project instructions file (CLAUDE.md) at the start of each session, a useful place to record conventions and architecture notes so every session starts with the same context.
3. A documentation pipeline
A scripted process that generates or refreshes documents for each module on a schedule or on each merge, combining static analysis output (call graphs, schemas, dependency lists) with model summaries, and opening a pull request for review.
4. A question-answering assistant over code and documents
A retrieval-based assistant that indexes code, documentation, tickets and runbooks, and answers questions with links to sources. Useful for operators and support staff who do not read code.
| Approach | Setup effort | Knowledge retained | Best for |
|---|---|---|---|
| Editor assistant | Low | Low unless written down | Individual engineers exploring code |
| Agentic repository tool | Low to medium | Medium (documents produced) | Producing an initial documentation set |
| Documentation pipeline | Medium | High (versioned, reviewed) | Keeping documentation current |
| Q&A assistant with retrieval | Medium to high | High (searchable) | Operators, support and onboarding at scale |
Most teams combine them: an agentic tool to produce the first draft, a pipeline to keep it current, and an assistant for people who need answers rather than documents. Rolling these tools out across a team raises governance questions we discuss in rolling out AI coding assistants across an engineering team.
Action: start with an agentic tool on one bounded module and judge the output against your question list before investing in a pipeline.
How do you give the model the right context?
Output quality depends heavily on what the model sees. Dumping an entire repository into one prompt is rarely the best approach: research by Liu and colleagues, Lost in the Middle, found that language models use information best when it appears near the start or end of a long input, and performance drops when the relevant part sits in the middle.
Practical context engineering
- Work module by module: document bounded areas, then write a higher-level overview from those summaries.
- Add structure from tools: feed in call graphs, database schemas, job schedules and dependency lists from static analysis rather than asking the model to infer them.
- Include history: commit messages, ticket references and incident notes explain why code changed.
- Provide a glossary: business terms, abbreviations and system names used in the code.
- Use a standard template: purpose, inputs and outputs, data touched, dependencies, failure modes, open questions.
- Ask for uncertainty: instruct the model to list what it could not determine rather than guessing.
Capture expert knowledge alongside code
Record short sessions with domain experts walking through key flows, transcribe them, and use the model to turn transcripts into structured notes linked to the relevant modules. The expert then reviews the notes. This is often the highest-value activity before someone leaves, and it captures rationale that code alone never reveals.
For example, a 15-person insurance IT team might spend two hours a week with a retiring developer for a quarter, turning each session into reviewed notes attached to the modules discussed. The numbers are illustrative; the pattern of short, regular, recorded sessions is what matters.
Action: build a context pack template for one module, including schema, call graph, glossary and recent history, and reuse it across the codebase.
How do you verify AI-generated documentation?
Verification is what turns generated text into documentation people can rely on.
- Automated cross-checks: confirm that every function, table and file a document references actually exists, and that described inputs and outputs match signatures and schemas.
- Question-based evaluation: run your question list against the documentation or assistant, and score answers as correct, partially correct or wrong.
- Test-backed claims: where a document states a business rule, link it to a test that proves it, or write one. Characterisation tests are a natural by-product of documenting legacy behaviour.
- Expert review: domain experts and senior engineers review high-risk areas such as money, compliance and data deletion.
- Status and ownership: each page shows its verification status, reviewer and date.
Keep it alive
Generated documentation goes stale like any other. Put documentation in the repository, regenerate affected sections when code changes, and require review as part of the normal pull request process. A short check in the pipeline can flag when code in a module has changed but its documentation has not.
Action: set a target, such as all high-risk modules human-verified within a quarter, and track it like any other engineering metric.
What are the security, cost and organisational risks?
Security and confidentiality
Legacy code often contains hard-coded credentials, internal hostnames and personal data in test fixtures. OWASP lists sensitive information disclosure among the top LLM application risks. Before sending code to any model:
- Scan for and remove secrets and personal data.
- Use enterprise agreements that exclude your data from training, or self-hosted models for the most sensitive code.
- Restrict which repositories each tool can access, and log usage.
- Check contractual obligations if the code belongs to, or was built for, a client.
Costs
Costs include tool licences or model usage, engineering time to build context packs and pipelines, and, most significantly, expert time for review. Budget for review explicitly; it is the part most often skipped.
Organisational risks
| Risk | Mitigation |
|---|---|
| Experts feel their role is being replaced | Position the work as capturing their legacy and reducing their support burden; credit them as reviewers |
| Over-trust in generated text | Visible verification status and question-based testing |
| Documentation sprawl | One template, one location, ownership per module |
| Effort fades after the first push | Pipeline integration and a named owner |
Knowledge transfer is also central when bringing in an external team; our plan for the first 90 days with a dedicated development team shows where documentation fits.
A step-by-step rollout plan
- Define outcomes and questions: agree the 30 to 50 questions and the systems in scope.
- Secure the setup: choose tools and model providers that meet your data policy; scan code for secrets.
- Pilot one module: generate documentation with a context pack and evaluate it against the relevant questions.
- Run expert sessions: record, transcribe and convert key walkthroughs into reviewed notes.
- Scale by risk: extend to high-risk and high-change modules first.
- Automate upkeep: add documentation refresh and review to the pull request pipeline.
- Add a Q&A assistant if operators and support staff need answers rather than documents, with sources linked.
- Measure: track onboarding time, verified coverage of high-risk modules, and incidents escalated to a single expert.
Readiness checklist
- Question list agreed with engineering and operations.
- Data policy for code and model providers approved.
- Secrets scan completed on in-scope repositories.
- Documentation template and location decided.
- Experts identified and time allocated for sessions and review.
- Verification status shown on every page.
- Owner named for ongoing upkeep.
If documentation is a prelude to replacing parts of the system, the same assets feed directly into incremental approaches such as the strangler fig pattern.
Frequently asked questions
Can AI document a legacy system without any human involvement?
It can produce useful drafts, but not trustworthy documentation on its own. Business intent, design rationale and edge cases need expert input, and every important claim should be verified against code, tests or people.
Is it safe to send our source code to an AI model?
It can be, with the right setup: enterprise terms that exclude your data from training, secrets removed before processing, access restricted by repository, and self-hosted models for the most sensitive code. Check any client or contractual obligations too.
Does this work for COBOL, RPG or other older languages?
Modern models can often explain older languages, especially well-known ones, but quality varies with how much public code exists in that language and how idiosyncratic your codebase is. Pilot on a representative module and verify carefully.
Should we generate documentation or build a Q&A assistant?
Usually both, in that order. Reviewed documentation is the reliable foundation; an assistant that retrieves from it, with source links, helps people who need quick answers rather than reading pages.
How do we measure whether knowledge transfer has worked?
Use the question list as a test, and track practical outcomes: time for a new engineer to make a first safe change, verified coverage of high-risk modules, and how often incidents still need the one expert.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- Nikolov et al., Google (2025): How is Google using AI for internal code migrations? — accessed 9 November 2026. Experience report describing evidence that LLMs can significantly reduce migration time on large codebases.
- Liu et al. (2023): Lost in the Middle: How Language Models Use Long Contexts — accessed 9 November 2026. Models use information at the start or end of long inputs better than in the middle, supporting module-by-module context.
- OWASP: Top 10 for LLM Applications 2025 — accessed 9 November 2026. Misinformation and sensitive information disclosure as key risks when relying on LLM output.
- Anthropic: Claude Code overview — accessed 9 November 2026. Example of an agentic coding tool that reads a codebase and uses a project instructions file for persistent context.
Related reading
Continue your research
Who understands your legacy system, and what happens when they leave?
We can pilot AI-assisted documentation on one of your critical modules, with verification and a secure setup, and show you what the output looks like.
