- Home
- Skills
- Data & Databases
- Trusted SQL Analyst: Text-to-SQL That Double-Checks
More screenshots
Works with the AI Agents you already use
Trusted SQL Analyst: Text-to-SQL That Double-Checks
The dangerous failures are queries that run fine and return a confident, wrong number.
$9.99
Trusted SQL Analyst: Text-to-SQL That Double-Checks
Example session with this skill installed
Using chinook.db in this folder: what are the top 3 music genres by sales revenue, and how much did each bring in? A colleague got Rock = 7,720.02 with this query - which number is right?
SELECT g.Name, SUM(i.Total) AS revenue
FROM Invoice i
JOIN InvoiceLine il ON il.InvoiceId = i.InvoiceId
JOIN Track t ON t.TrackId = il.TrackId
JOIN Genre g ON g.GenreId = t.GenreId
GROUP BY g.Name
ORDER BY revenue DESC
- Read your context and instructions
- Compiled the trusted sql analyst
The top 3 genres by sales revenue are Rock (826.65), Latin (382.14) and Metal (261.36), across all sales from 2009-01-01 to 2013-12-22. Your colleague's Rock = 7,720.02 is wrong. It is about 9.3 times too high.
Together these three genres account for 1,470.15 (63.1%) of total sales of 2,328.60. Rock alone is about 35.5%.
| rank | genre | revenue | share of all sales | tracks sold |
|---|---|---|---|---|
| 1 | Rock | 826.65 | 35.5% | 835 |
| 2 | Latin | 382.14 | 16.4% | 386 |
| 3 | Metal | 261.36 | 11.2% | 264 |
(21 more genres had sales. Opera had none.)
Why the colleague's number is wrong
The query adds up Invoice.Total, which is the total of a whole invoice, after joining each invoice to its individual track lines. An invoice with 9 tracks therefore has its full total counted 9 times. It also gets credited in full to every genre on that invoice, even when only one of its tracks was Rock. On average each invoice is counted 5.44 times (2,240 lines across 412 invoices). As a result the colleague's genre figures add up to 20,848.62, while the store only took in 2,328.60. Even counting each invoice with a Rock track only once would give 1,639.03, which is still wrong because those invoices include other genres. The correct method adds up only the price of the Rock track lines themselves.
How this was calculated
Every sold track line (InvoiceLine) was matched to its track and that track's genre. Then price × quantity was summed per genre. All invoices in the database were included, with no date filter.
Assumptions
- Revenue = unit price × quantity on each invoice line. The database has no discount, tax, refund or cancellation fields, and every invoice total equals the sum of its lines exactly. This definition and invoice totals therefore give the same overall figure.
- "Music genres" = the Genre table as stored. A few entries are video categories (TV Shows, Drama, Sci Fi & Fantasy, etc.), but none of them is in the top 3, so the answer does not change.
- No currency is stored in the data. Amounts are in the store's currency units.
- Data covers invoices from 2009-01-01 to 2013-12-22.
Checks
- Query check: PASS for the corrected query. The colleague's query FAILs the fan-out check: each Invoice row appears 5.44 times after the joins, so SUM(i.Total) counts the same invoices several times.
- Cross-check: a second query built a different way (starting from each genre and using subqueries instead of joins) AGREES on all 24 genres. Comparing the colleague's query with the corrected one, all 24 genre values differ.
- Reconciliation: the 24 genre totals add up to 2,328.60, which equals the sum of all invoice totals (2,328.60). All 412 invoices match their line items to the cent.
- Data issues: none found. Every invoice line links to a track and every track links to a genre, so no sales are dropped. There are no zero or negative prices or quantities.
SELECT g.Name AS genre,
ROUND(SUM(il.UnitPrice * il.Quantity), 2) AS revenue
FROM InvoiceLine il
JOIN Track t ON t.TrackId = il.TrackId
JOIN Genre g ON g.GenreId = t.GenreId
GROUP BY g.GenreId, g.Name
ORDER BY revenue DESC
LIMIT 3;
</details>
Connects securely to your tools. The creator never sees your data.
About this skill
Your agent answers data questions with SQL - and proves the number before you trust it.
Natural-language-to-SQL is not solved. The dangerous failures are queries that run fine and return a confident, wrong number. Trusted SQL Analyst makes your agent work like a careful senior analyst.
What it does
- Maps the database - tables, keys, measured joins (orphans, NULL keys, one-to-many), messy values ('USA' vs 'usa '), how dates are stored.
- Pins down the question with a glossary: metric definition, grain, time window, what "active" or "revenue" means.
- Writes the SQL, then runs 25 checks on the query and on its real result - with numbers, not guesses.
- Proves the number with a second query written a different way, and compares them.
- Answers in plain English: the number, how it was calculated, the assumptions, the checks done, and the SQL.
Example
"Revenue by genre" on the Chinook sample database. The obvious query sums the invoice total after joining to invoice lines: Rock = 7,720.02. The real figure is 826.65. The check: FAIL - each Invoice row appears 5.44 times on average after the joins (2,240 joined rows for 412 invoices).
What it checks
- Joins: fan-out double counting (with the measured factor), rows dropped by INNER JOIN, joins without a condition, LEFT JOIN undone by WHERE, COUNT(*) after LEFT JOIN
- NULLs: NOT IN with a NULL in the subquery,
= NULL,<>/NOT LIKEsilently dropping NULL rows - Text: case/space mismatches, values that do not exist (closest matches shown), LIKE that also matches other categories, comma-separated lists matched with
= - Dates: BETWEEN /
<=dropping the last day when values have a time,=on timestamps, non-ISO date text - Grouping & maths: non-grouped columns, grouping by a name that merges different people, integer division, AND/OR without brackets, LIMIT without ORDER BY
- The result itself: which filter emptied it, duplicate groups, totals that do not add up, impossible percentages
Tested honestly
- Blind test: a separate AI that never saw the tool wrote 24 new wrong queries on three real databases (Chinook, Northwind with 609k order lines, Sakila). Frozen checker, run once: 14 of 16 SQL-mechanics mistakes caught; 0 of 8 business-meaning mistakes (wrong column or definition - no checker can see those from SQL; the glossary and second-query steps are there for them); 2 of 24 correct queries got a REVIEW note.
- 32 development cases: 31 of 32 wrong queries flagged, 0 correct queries flagged.
- 46 automated tests on Python 3.9 to 3.13.
- Every number and example: results page
Works with
SQLite, DuckDB, CSV/Parquet/Excel folders (via DuckDB), Postgres and MySQL (via SQLAlchemy). Read-only: it refuses INSERT/UPDATE/DELETE/DDL, file-reading functions and multiple statements, and every query has a timeout. Tested on SQLite and DuckDB.
Also great for
Reviewing SQL written by a colleague or another AI: the problems, the measured impact and a fixed query.
What you get
SKILL.md workflow · sqlanalyst.py (profile, run, check, compare) · a trap reference with wrong vs right SQL for every check · a question checklist · dialect notes · an answer template.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.
It cannot know your business meaning: a query that uses the wrong column or definition is valid SQL for a different question (0 of 8 such mistakes were caught in the blind test) - the glossary and second-query steps exist for those. Read-only: it answers questions and never changes data. Postgres/MySQL work through SQLAlchemy but were not tested on a live server; tested on SQLite and DuckDB.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 1 day ago
- Software
Python 3.9+sqlglot (pip install sqlglot)
- Optional
- duckdb (CSV, Parquet, Excel and DuckDB files)SQLAlchemya driver (Postgres, MySQL)
Runs on your machine. Needs `pip install sqlglot`; if it is missing, the helper says so and your agent can install it. Database URLs and file paths stay in your session.
Permissions
File Scopes
Terminal: runs one local Python helper (profile, run, check, compare). Read files: your database file or CSV/Parquet/Excel folder (read-only; writes, file-reading SQL functions and multiple statements are refused). Write files: notes in .sqlanalyst/ (database map, glossary, query drafts). The helper makes no network calls; connecting to a database server uses the URL you give.