Governed Text-to-SQL for Finance Teams
Natural-language to SQL with schema awareness, role-based access control, KPI glossary, and audit logging. Python, Flask, Snowflake, LLM API.
User Question
→
Auth / RBAC
→
Schema Resolver
→
SQL Generator
→
Safety Validator
→
Snowflake
→
Results + Audit
20+
Analyst hours freed/week
3-5 days
Reduced to seconds
Try a Query
Query Blocked by Safety Validator
Role-Based Access Control
Schemas: finance_reporting
Views: v_revenue, v_opex, v_margin_by_division
Schemas: finance_reporting, finance_detail
Views: + v_journal_entries, v_trial_balance
Schemas: finance_reporting, finance_detail
Views: all views, no filter restrictions
KPI Glossary (Governed Definitions)
| KPI | SQL Definition | Grain | Source View |
| Gross Margin | (SUM(revenue) - SUM(cogs)) / NULLIF(SUM(revenue), 0) | division, month | v_revenue |
| Net Revenue | SUM(revenue) | division, month | v_revenue |
| OPEX Variance | SUM(actual_opex) - SUM(budget_opex) | cost_center, month | v_opex |
| OPEX Variance % | (actual - budget) / NULLIF(budget, 0) | cost_center, month | v_opex |
| Revenue per Unit | SUM(revenue) / NULLIF(SUM(units_sold), 0) | division, product, month | v_revenue |
Safety Rules (6 validation checks)
| Rule | What it blocks | Tests |
| SELECT only | Any non-SELECT statement (DROP, DELETE, INSERT, UPDATE) | 4 passing |
| Blocked keywords | DDL/DML keywords even inside SELECT statements | 2 passing |
| Table authorization | Queries referencing tables outside the user's authorized schema | 2 passing |
| No SELECT * | Wildcard selects (must name columns explicitly) | 2 passing |
| Fact table WHERE | Queries on large fact tables without a WHERE clause | 2 passing |
| Injection patterns | Multi-statement, SQL comments, INFORMATION_SCHEMA access | 3 passing |
Audit Trail (last 5 queries)
| Timestamp | User | Role | Question | Status |
| 2024-03-15 09:14:22 | jsmith | fpa_analyst | Gross margin by division Q3 | Success |
| 2024-03-15 09:12:05 | mchen | controller | Journal entries for account 5100 | Success |
| 2024-03-15 09:08:41 | test_user | fpa_analyst | SELECT * FROM secret_salaries | Blocked |
| 2024-03-15 08:55:19 | jsmith | fpa_analyst | Net revenue by product line YTD | Success |
| 2024-03-15 08:42:33 | cfo_user | cfo | OPEX variance all cost centers | Success |
Interactive demo with simulated responses. Source: github.com/nicholasjh-work/llm-text-to-sql-finance