Natural language → semantic reasoning → validated SQL → decision-ready answer, with evidence.
GenQuery-AI explores how to build a natural-language analytics system as a reliable agentic application, not just an LLM prompt. Snowflake is the controlled execution layer; the customer-facing product is the interpreted answer.
The core pipeline is:
Business question
↓
Intent / Semantic resolution
↓
Adaptive RAG
↓
Semantic Graph
↓
Query Plan IR
↓
Validation / Safety
↓
SQL Compiler
↓
Snowflake (controlled execution)
↓
Result Interpreter
↓
Answer Planner
↓
Decision-ready Answer
├── Executive / KPI
├── Chart / Trend
├── Comparison
├── Insight / anomaly
├── Table
└── Raw data / SQL for audit
↓
Evidence
A useful SQL agent has to solve more than generation quality. It needs to handle schema grounding, unsafe output, provider failures, latency, caching, observability, and regression testing.
This repository is a practical exploration of those engineering boundaries.
- Schema-aware RAG — retrieve relevant tables/columns before generation
- Multi-provider inference — cloud and local providers with fallback support
- SQL safety — read-only policy, DDL/DML blocking, multi-statement checks
- Query recovery — validation and regeneration paths for failed queries
- Semantic caching — reduce repeated inference for similar requests
- Telemetry — provider, latency, cache, execution and feedback signals
- Evaluation — regression methodology for SQL correctness, answer generation and system behavior
- Answer Intelligence — decision-ready summaries, KPIs, charts, trends, comparisons and insights
- Evidence — customer claims remain linked to structured retrieval/plan/execution artifacts
- Snowflake integration — schema introspection and controlled execution
┌─────────────────┐
│ Natural Language│
│ Question │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Intent / Context│
└────────┬────────┘
│
▼
┌─────────────────┐
│ Schema Retrieval│
│ (RAG) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ LLM Provider │
│ + fallback path │
└────────┬────────┘
│
▼
┌─────────────────┐
│ SQL Validation │
│ + safety gate │
└────────┬────────┘
│
safe SQL only
│
▼
┌─────────────────┐
│ Snowflake │
│ read-only role │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Result + Metrics│
└─────────────────┘
- Python 3.10+ (Python 3.11 recommended)
- Snowflake account with a least-privilege read-only role
- At least one supported LLM provider, or a local provider such as Ollama
git clone https://github.com/rohith0707/GenQuery-AI.git
cd GenQuery-AI
python -m venv .venvWindows:
.venv\Scripts\activatemacOS/Linux:
source .venv/bin/activatepip install -r requirements.txt
cp .env.example .env
streamlit run app.pyOn Windows, copy .env.example to .env manually if cp is unavailable.
.env.example contains placeholders only. Never commit real API keys or database credentials.
Use a dedicated read-only Snowflake role. The application should not be given write privileges merely because generated SQL comes from a trusted-looking prompt.
The raw Snowflake DataFrame is treated as an internal execution artifact. The customer receives an Answer Artifact that can be rendered as:
| View | Typical question |
|---|---|
| Executive | What happened to revenue? |
| KPI | What is revenue? |
| Chart | Show revenue by region |
| Trend | How has revenue changed over time? |
| Comparison | Compare Hyderabad vs Bangalore |
| Insight | Why did revenue fall? |
| Table | Show grouped results |
| Raw | Show underlying data / SQL |
The answer layer is deterministic today: it inspects the result shape, selects an appropriate view, produces KPIs/comparisons/trend data, flags simple statistical outliers, and keeps evidence attached. Deeper causal reasoning is intentionally not claimed without supporting evidence.
The Agent Workspace lets an operator switch between customer-facing views while retaining evidence and an explicit raw-data/audit path.
The project treats evaluation as an engineering artifact. See docs/EVALUATION.md.
The benchmark methodology separates:
- SQL validity
- task correctness
- schema grounding
- safety
- robustness
- latency
- cost
Failed cases should be categorized by failure mode rather than hidden behind a single accuracy number.
See docs/ARCHITECTURE_DECISIONS.md for the reasoning behind schema retrieval, validation, read-only execution, provider fallback, telemetry, and system-level evaluation.
The application is designed around least privilege:
- Generated SQL is validated before execution.
- DDL/DML operations are blocked.
- Multi-statement execution is rejected.
- Snowflake should use a read-only role.
- Credentials belong in environment variables, never source control.
- Query-result limits reduce accidental large reads.
This is application-level protection, not a substitute for Snowflake network, identity, permission, and monitoring controls.
This is an engineering project, not a claim of perfect text-to-SQL accuracy. Known limitations include:
- model output remains probabilistic
- retrieval errors can propagate into SQL generation
- SQL validation is necessarily incomplete compared with a full database security boundary
- query cost is currently a heuristic before execution rather than Snowflake EXPLAIN-backed
- answer interpretation is deterministic and deliberately conservative today
- provider behavior varies across models and versions
The goal is to make those failure modes measurable and progressively reduce them.
- Public regression dataset with versioned cases
- Automated benchmark runner
- Model/provider comparison dashboard
- Execution-cost estimation with Snowflake EXPLAIN
- Better retrieval evaluation
- CI evaluation gate for regression cases
- Container deployment path
- Customer-facing answer artifacts
- FastAPI service layer alongside the Streamlit UI
Latest main commits now include the benchmark/deployment loop and customer-answer intelligence:
| Commit | Change |
|---|---|
| 6c36473e | docs: document answer intelligence benchmarks |
| 68a18aac | docs: document answer intelligence and latest main commits |
| fecef027 | test: cover answer benchmark metrics |
| e3074372 | feat: benchmark customer answer artifacts |
| d818e73f | feat: render customer-facing answer views |
| 74a332e8 | feat: support multiple answer render views |
| 23d56e51 | feat: add answer artifact contract |
| f8e1215c | test: evaluate customer-facing answer artifacts |
| 95fb6be8 | feat: add customer answer intelligence |
| 7f033137 | deploy: add container health check |
| 8bb47801 | ci: run benchmark regression without model dependency |
| 4781f9bb | feat: link benchmark workspace |
| 2f302029 | fix: separate static and live benchmark modes |
No license is currently declared. Do not assume the code is licensed for unrestricted reuse.
The current main branch includes an inspectable agentic workflow:
Question → Adaptive RAG → Semantic Graph → Query Plan IR → Validation → SQL Compiler → Execution → Result Interpretation → Answer Artifact → Evidence
Open Agent Workspace from the Streamlit pages to inspect the structured plan, retrieval sources, semantic graph, validation gates, compiled SQL, customer-facing answer views and optional raw-data/audit output.