- Home
- Skills
- Data & Databases
- NL2SQL Finance Analytics & Read-Only Data Auditor
NL2SQL Finance Analytics & Read-Only Data Auditor
Across 80 test queries with multi-table joins, CTEs, and window functions, this self-correcting setup hit **92.5% execution accuracy** without allowing a single write operation.
$9
Works with the AI Agents you already use
NL2SQL Finance Analytics & Read-Only Data Auditor
Example session with this skill installed
Audit our ledger_charges and invoices tables in billing.db. Find any customers who were charged more than once for the same invoice where the charge succeeded, and show the total duplicate dollar impact.
- Read your context and instructions
- Compiled the nl2sql finance analytics
- Schema Check: Queries sqlite_master on billing.db and confirms ledger_charges(charge_id, customer_id, invoice_id, amount_cents, status, created_at) stores amounts in integer cents.
- Draft & SQLGlot AST Check: Runs python3 scripts/sqlglot_guardrail.py --dialect sqlite --max-limit 500 on the CTE query using COUNT(*) OVER and ROW_NUMBER() OVER partitioned by (customer_id, invoice_id, amount_cents). Output: {"valid": true, "dialect": "sqlite", "message": "Passed SQLGlot read-only AST check."}
- Verified Output: Identified 3 duplicate succeeded charges across 2 enterprise invoices (INV-9041, INV-8812), totaling $1,450.00 USD in overbilled revenue requiring refund credit notes, while blocking any DELETE statements.
Connects securely to your tools. The creator never sees your data.
About this skill
I built this skill out of my open-source project nl2sql-analytics-agent after dealing with two recurring headaches when letting coding agents query financial tables: hallucinated column names on multi-table joins, and brittle regex filters that miss destructive SQL inside subqueries or CTEs.
This package gives your agent (Claude Code, Cursor, Codex, Gemini CLI) a reliable workflow to turn plain-English finance, billing, and revenue questions into verified SQL over PostgreSQL and SQLite. Across 80 test queries with multi-table joins, CTEs, and window functions, this self-correcting setup hit 92.5% execution accuracy without allowing a single write operation.
How It Works
- Checks the Live Schema First: Before writing any SQL, the agent queries
sqlite_masterorinformation_schema.columnsand samples 3 rows so it knows whether money is stored in cents or whole dollars, how dates are formatted, and what status values actually exist. - Writes Clean Analytical SQL: Builds readable CTEs and window functions (
LAG,LEAD,ROW_NUMBER() OVER) for MRR waterfalls, cohort retention, duplicate charge checks, and invoice-to-ledger reconciliation. - Validates the AST with SQLGlot (
scripts/sqlglot_guardrail.py):- Parses every query into an Abstract Syntax Tree using
sqlglotbefore execution. - Blocks stacked queries and any statement containing
DROP,DELETE,UPDATE,INSERT,ALTER,CREATE,TRUNCATE,GRANT,REVOKE, orPRAGMA. - Enforces a default
LIMIT 500on top-levelSELECTqueries so accidental full-table scans do not lock your database.
- Parses every query into an Abstract Syntax Tree using
- Fixes Its Own Schema Errors (
scripts/self_correcting_runner.py):- Opens SQLite files in strict read-only URI mode (
?mode=ro). - If a query fails with an
OperationalError(like a wrong column name or dialect function mismatch), it feeds the traceback and table DDL back to the agent to fix and re-validate the query (up to 3 retries).
- Opens SQLite files in strict read-only URI mode (
What Is Included in the ZIP
SKILL.md: Step-by-step instructions and guardrails for your agent.scripts/sqlglot_guardrail.py: Standalone Python CLI validator for read-only AST checking andLIMITenforcement acrosssqlite,postgres,duckdb,mysql,snowflake, andbigquery.scripts/self_correcting_runner.py: Read-only SQLite runner that returns structured schema DDL hints when a query fails.references/finance-sql-patterns.md: Ready-to-use SQL patterns for duplicate charge audits, monthly MRR waterfall (New, Expansion, Contraction), and invoice-to-ledger variance checks.references/setup-and-compatibility.md: Quick local setup notes and link to the fullnl2sql-analytics-agentrepo.
Limitations
- Read-Only by Design: This skill only runs
SELECTqueries. It will refuse to write or runINSERT,UPDATE,DELETE, or schema migrations. - Local Python Dependency: Requires Python 3.10+ with
sqlglotandpydanticinstalled locally (pip install sqlglot pydantic) plus access to your SQLite file or PostgreSQL read replica.
Strictly read-only SELECT execution (blocks INSERT, UPDATE, DELETE, DROP, ALTER). Requires local Python 3.10+ with sqlglot and pydantic installed.
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 any payment.
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 5 days ago
Requires