DB Context Generato
r for AI
A lightweight Python-based utility designed to bridge the gap between your database schema and Large Language Models (LLMs). It extracts metadata from your database and generates a compact, readable text context (prompt) that helps AI assistants understand your table structures without executing actual SQL queries or sharing sensitive data.
Link – github.com
Key Features
- Modular Architecture: Automatically discovers database drivers (any
db_*.pyfile) in the current directory. - Intelligent Extraction: Instead of dumping the entire schema, it identifies relevant tables by scanning your input (SQL snippets, notes, or lists) for table names using case-insensitive substring matching.
- AI-Optimized Output: Generates a clean, DDL-free summary including table comments, column types, primary keys, and descriptions.
- Independent Configuration: Saves connection settings for each database engine separately in their own sections within the
config.inifile. - Manual Save Control: Settings are only committed to the configuration file when you explicitly click the save button.
- Cross-Platform GUI: Easy-to-use interface built with Tkinter, fully translated into English.
Supported Databases
- Firebird (versions 2.5, 3.0, 4.0)
- MySQL (versions 5.7, 8.0)
Installation
Prerequisites
- Python 3.x
- Firebird client library (
fbclient.dllorlibfbclient.so) if using Firebird.
Dependencies
Install the required Python packages:
pip install fdb pymysql
How It Works
Scanning: On startup, the app loads all db_*.py modules found in the application folder.
Filtering: The utility retrieves the full list of table names from the connected database. It then checks the Input Data field; if a table name is found as a standalone word or surrounded by common delimiters within your text, that table’s metadata is included in the prompt.
Prompt Generation: It compiles the table descriptions and column details into a structured text block ready for copying into AI chat interfaces.
Usage
Configure Connection: Select your DBMS from the dropdown, then enter the host, port, database name, and credentials.
Test & Save: Click Test Connection to verify settings. Click Save Settings to store them permanently in config.ini.
Provide Context: Paste your SQL query or a list of tables you are working with into the Input Data box.
Generate: Click Generate AI Context.
Copy: Click Copy to Clipboard and paste the result into your AI chat.
Project Structure
- main.py: The core GUI application and logic controller.
- db_firebird.py: Driver for Firebird database connection and metadata extraction.
- db_mysql.py: Driver for MySQL database connection and metadata extraction.
- config.ini: Automatically generated file for persistent settings.
Example Prompt Output
Database: MySQL 8.0.32
Table: USERS — System users table
- ID (int, PK) — Unique identifier
- LOGIN (varchar(50), NOT NULL) — User login
- EMAIL (varchar(255)) — Contact email
Table: ORDERS — Customer orders
- ID (int, PK)
- USER_ID (int) — Foreign key to USERS
- TOTAL (decimal(10,2))
