info@lasmart.biz

june 21, 2025

Using LLM to automatically generate documentation for a database

High-quality database documentation is an essential part of a successful project. It offers a number of key benefits:

  • Simplifies and speeds up onboarding for new developers.
  • Facilitates faster development and reduces the risk of errors.
  • Minimises risks related to team turnover.
  • Increases transparency for the business.

However, manual documentation is a time-consuming and costly process that requires highly skilled staff. Moreover, documentation created manually tends to become outdated quickly.

To address this problem, we developed a tool that automates and accelerates the documentation process while reducing its cost by minimising manual effort. In designing the application, we focused on the following key requirements:

  • Ease of deployment: integrating the tool into a project should require minimal effort.
  • User-friendly interface: the tool should be accessible to users of any skill level.
  • Ease of working with documentation: the documentation structure should be intuitive and easy to read.
  • Support for various database engines.

Solution architecture

At the core of our solution are large language models (LLMs), which significantly accelerate the documentation process thanks to their efficiency. We chose to use local open-source LLMs — a decision driven by the need to maintain data confidentiality, as all information remains within the project’s infrastructure.

The key advantage of LLMs over existing documentation generation systems lies in their flexibility and depth. Traditional systems operate on rigid templates and rules, often requiring manual adjustments when data deviates from a predefined structure. Their output is typically limited to templated language lacking meaningful explanation or logic.

LLMs, on the other hand, generate documentation with explanations and examples, increasing its value. Moreover, changing the documentation format requires minimal effort. Unlike outdated approaches, LLMs combine the speed of automation with the quality of manual review, making the documentation process both faster and more useful to end users.

During development, we tested several LLMs of different architectures and sizes. Model selection was based on the following criteria:

▶︎ Descriptive accuracy: alignment of the generated documentation with the actual structure of the database.
▶︎ Consistency: adherence to a unified style and documentation format.
▶︎ Minimisation of hallucinations: avoiding inaccurate or fabricated content.

The highest quality was demonstrated by two models — Qwen2.5 and Mistral:

Qwen

Handles the initial documentation generation for all database objects: tables, views, functions, and procedures

Mistral

Enhances table descriptions by adding contextual insights derived from the data

To generate documentation, we use SQL scripts that define the core database objects. The script for each table is supplemented with a random sample of 10 data rows. However, this data alone does not provide the model with enough context to understand the task. That’s why additional context is included in the script. This context helps guide the LLM to produce the desired results by specifying:

  • The format of the input data;
  • The type of object in the input;
  • The task the model should perform and a clarification of the requirements;
  • The expected structure and an example of the output;
  • The language and style of the result.

Thanks to this contextual prompt, the model stays focused — avoiding generic commentary on SQL syntax — and concentrates on the key components of the scripts, generating a structured and relevant output.

The generated content can be easily converted into any preferred format: JSON, HTML, Markdown, or PDF.

The diagram below shows the workflow for generating documentation:

Results

The developed tool has proven effective across several projects. Its key advantage is ease of integration: deployment typically takes no more than four hours. In addition, it delivers high performance — reducing the time required to create documentation by a factor of 20 or more compared to manual methods. A database containing 1,000 objects was fully documented in four hours, with an error rate of less than 5%.

The tool is especially efficient when working with large volumes of data — databases containing hundreds or thousands of objects. Manual processing would take several weeks, whereas LLMs complete the task within hours. Processing time scales linearly with the size of the database structure, without unexpected delays. The tool is particularly valuable in environments where database objects change frequently, as it keeps the documentation automatically up to date.

For more information, please get in touch here:

Contact Form main