# Text-to-SQL BI Assistant: PostgreSQL, MySQL, SQLite, CSV

> Ask business questions in plain English or French about your PostgreSQL, MySQL/MariaDB or SQLite database, or your CSV exports. Your agent reads the schema, writes the SQL, runs it read-only behind a safety guard, and answers with the figures, the table and the query.

Text-to-SQL BI Assistant: PostgreSQL, MySQL, SQLite, CSV is a paid AI agent skill on Agensi by Medhedi Chebil, in Business & Operations. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Medhedi Chebil](https://www.agensi.io/creators/medhedi-chebil)
- Category: [Business & Operations](https://www.agensi.io/skills/business-operations)
- Version: 1.0
- Last updated: 2026-12-03
- Security: scan passed (2026-12-03); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/text-to-sql-bi-assistant-postgresql-mysql-sqlite-csv
- Tags: business-operations, sqlite, csv-analysis, data-analysis, kpi-tracking

## What it does

- Answers business questions (revenue, margins, rankings, trends) by writing and running SQL on your data
- Reads your schema first: tables, join paths, real category values and number ranges
- Blocks every write: only one SELECT runs, on a read-only connection, with time and row limits
- Connects to PostgreSQL and MySQL/MariaDB servers, SQLite files or CSV exports
- Learns your metrics: saves the answers you confirm and reuses them for similar questions

## Who it's for

- **Business and data analysts:** Ad-hoc questions answered with the SQL shown, so every figure can be checked and reused. Try: "Which products had the highest profit margins last month?"
- **Small business owners:** Figures from your sales exports without writing SQL or waiting for a dashboard. Try: "Which month of 2025 had the highest revenue, and how does it compare with the same month in 2024?"
- **Developers and BI students:** A safe way to explore a PostgreSQL, MySQL or SQLite database or star schema from their agent. Try: "Quel est le chiffre d'affaires par catégorie pour 2024 ?"

## About this skill

### Ask your data questions, get checked answers

"Which store had the best margin in 2025?" "Top 5 B2B customers?" "Quel est le CA par catégorie ?" Ask in plain English or French. Your agent reads your database schema, writes one SQL query in the right dialect, runs it **read-only**, and answers with the key figures, the result table and the SQL it used.

### Works on your data

- **PostgreSQL** and **MySQL / MariaDB** servers
- **SQLite** files (.sqlite, .db)
- **CSV exports**: one command turns a folder of CSV files into a database (delimiter and column types detected, codes like 007 kept as text)

Your server password never appears in commands or answers: the connection URL is read from an environment variable and masked in error messages.

### Cannot change your data

- Only one `SELECT` (or `WITH … SELECT`) statement is accepted
- **PostgreSQL and MySQL:** every query runs in a READ ONLY transaction that is always rolled back; system schemas and risky server functions (`pg_read_file`, `INTO OUTFILE`, `LOAD_FILE`, `SLEEP`, locks…) are refused
- **SQLite:** the file is opened read-only and an authorizer blocks writes, `PRAGMA`, `ATTACH` and system tables
- Queries stop after 10 seconds and results are capped at 200 rows
- You can hide tables, for example a table with personal data

If the guard refuses a query, the agent stops and tells you: it never tries to work around it. For the strongest protection on a server, connect with a database user that has SELECT rights only.

### Gets better with use

Answers you confirm are saved in a small example bank for that database. The closest examples are retrieved for each new question, so your own metric definitions are reused. It works offline, in English and French.

### Easy to try

A demo retail warehouse (60,000 sales lines, 2024–2025, 32 solved questions) lets you try it in one minute, with no database to set up.

### Limits

SQL Server, Oracle and other databases are not connected directly: export the tables to CSV first.

## Requires

- Python 3.9+
- Optional: PostgreSQL
- Optional: MySQL

## Known limitations

Works with PostgreSQL, MySQL/MariaDB, SQLite and CSV. SQL Server, Oracle and other databases are not connected directly: export the tables to CSV first. One query per question, read-only, stopped after 10 seconds and capped at 200 rows (both adjustable). Example search matches shared words, not meaning, so it helps most when questions are phrased like earlier ones.

## Technical details

Python 3.9+, no API key. SQLite/CSV: standard library only. PostgreSQL: pip install "psycopg[binary]". MySQL/MariaDB: pip install pymysql. Server URLs are read from an environment variable (env:DATABASE_URL) and masked in errors. Scripts: inspect_db.py (dialect, schema, join paths, real values), run_query.py (exit codes 0 OK, 1 error, 2 refused), examples.py (per-database bank of verified question-to-SQL pairs, local embedder), csv_to_sqlite.py. Guard: one SELECT/WITH; SQLite read-only file + authorizer; PostgreSQL/MySQL READ ONLY transaction always rolled back, system schemas and file/session/lock functions refused; table allowlist; timeout; row cap. Tested on PostgreSQL 16 and MariaDB 10.11.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Text-to-SQL BI Assistant: PostgreSQL, MySQL, SQLite, CSV skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Which databases and files does it work with?

PostgreSQL, MySQL and MariaDB servers, SQLite files (.sqlite, .db) and CSV files. CSV files are turned into a SQLite database with one command. For SQL Server, Oracle or other databases, export the tables to CSV first.

### What exactly do I get back after I ask a question?

A short answer with the key figures, the result table, the SQL query that produced it, and any assumption the agent made (for example, whether revenue is before or after discounts). You can also save the full result as a CSV file.

### Can the agent change or delete my data?

The skill only runs single SELECT queries. On PostgreSQL and MySQL each query runs in a READ ONLY transaction that is always rolled back, and risky server functions and system schemas are refused. On SQLite the file is opened read-only. If a query is refused, the agent stops instead of trying another way. For the strongest protection, connect to a server with a database user that only has SELECT rights.

### How do I connect my PostgreSQL or MySQL database?

Install the driver once (pip install "psycopg[binary]" for PostgreSQL, pip install pymysql for MySQL/MariaDB), then put your connection URL in an environment variable such as DATABASE_URL in your own terminal. The agent uses env:DATABASE_URL, so your password never appears in commands, files or answers, and it is masked in error messages.

### How should I phrase my questions?

As you would ask an analyst, in English or French: "Revenue by category in 2025", "Top 5 customers by margin", "Quel magasin a la meilleure marge ?". Name the period and the measure when you can. If a term is ambiguous, the agent asks one short question or states the assumption it made.

### Does it learn my business metrics over time?

Yes, from answers you confirm. When you say an answer is right, the question and its SQL are saved in a small example file for that database, kept on your computer. For each new question, the closest saved examples are reused, so your own definitions (margin, active customer, fiscal year) are applied consistently.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
