CoolFace
Apppublic

prazy1208/text2sql

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿ” Privacy-Preserving Natural Language Querying via Schema-Driven Agent Pipelines

๐Ÿ“Œ Overview

This project enables non-technical users to explore data using natural language without ever exposing sensitive data to external systems.

Traditional natural language querying systems often rely on direct access to datasets, which introduces privacy risks. This project takes a fundamentally different approach:

๐Ÿ‘‰ All query generation is performed using schema metadata only (table names, column descriptions, relationships, and business context). ๐Ÿ‘‰ No raw data is ever shared with Large Language Models (LLMs).

By treating privacy as a first-class constraint, the system ensures safe and controlled query generation while maintaining usability and flexibility.

๐Ÿง  Key Idea: Schema-Only Reasoning

Instead of sending actual data to the model, the system uses:

  • โ€”Table schemas
  • โ€”Column descriptions
  • โ€”Relationships between tables
  • โ€”Business context metadata

This allows the LLM to:

  • โ€”Understand user intent
  • โ€”Generate accurate structured queries
  • โ€”Maintain strict data privacy

โš™๏ธ Architecture

The system is built as an LLM-powered, agent-driven pipeline that decomposes the problem into modular stages:

๐Ÿ”„ Pipeline Stages

  1. 1.Intent Interpretation
  2. 2.Understands the user's natural language query
  1. 1.Schema-Aware Table Selection
  2. 2.Identifies relevant tables using metadata
  1. 1.Column Selection & Filtering
  2. 2.Narrows down to required fields
  1. 1.Contextual Grounding
  2. 2.Uses validated examples and business logic
  1. 1.Structured Query Generation
  2. 2.Produces SQL (or equivalent structured query)

๐Ÿ—๏ธ Design Principles

๐Ÿ” Privacy First

  • โ€”No raw data exposure at any stage
  • โ€”Schema-only interaction with LLMs
  • โ€”Safe for sensitive enterprise environments

๐Ÿ”Œ Execution-Agnostic

  • โ€”Query generation is decoupled from execution

๐Ÿงฉ Modular Agent Design

  • โ€”Each stage is handled by a dedicated agent
  • โ€”Improves interpretability and debugging
  • โ€”Enables independent optimization of components

โฑ๏ธ Performance

  • โ€”Handles moderately complex analytical queries
  • โ€”End-to-end pipeline latency: ~30โ€“50 seconds

๐Ÿงช Data Usage

  • โ€”Uses synthetic or publicly available datasets only
  • โ€”No real or sensitive data is included in this project

Documentation

DocumentContents
docs/PROJECT_STRUCTURE.mdRepository layout, backend conventions, how routes are organized
docs/CHAT_UI_AND_SESSIONS.mdMulti-chat sidebar, session/chat REST API, Postgres fields, browser localStorage keys
docs/MULTI_CHAT_SIDEBAR_PLAN.mdShort status pointer for the multi-chat implementation
docs/BACKFILL_SESSIONS.mdSQL backfill for sessions.title and optional client_id
docs/SUPABASE_SETUP.mdHosted Postgres (Supabase) connection and schema
docs/STAGE1_FINALIZED_PLAN.mdStage 1 app schema and Intent pipeline scope

Repository layout (summary)

  • โ€”`backend/` โ€” FastAPI entrypoint `backend/api/main.py`, agents under backend/agents/, shared services under backend/services/, HTTP routes under backend/api/routes/ (including `query.py`: /query, /session, /sessions, session messages).
  • โ€”`frontend/` โ€” Static chat UI (index.html, app.js, styles.css) served at /.
  • โ€”`scripts/` โ€” Database DDL such as `scripts/create_app_schema.sql`.
  • โ€”`docs/` โ€” Setup guides and architecture notes.

Running locally

From the project root (requires .env with DATABASE_URL and an LLM API key):

bash
uvicorn backend.api.main:app --reload

Then open http://127.0.0.1:8000/ for the chat UI. Apply scripts/create_app_schema.sql (or your full setup script) so app_schema.sessions and chat_messages exist.

๐Ÿš€ Future Scope

  • โ€”Introduce caching mechanisms to optimize repeated query performance
  • โ€”Extend conversational memory and structured persistence for richer reload fidelity
  • โ€”Refine back-and-forth querying (e.g. intent flows across session switches)