Query Sentinel ,Secure, Guardrailed Text-to-SQL System
Query Sentinel is a security-focused Text-to-SQL system that enables users to query relational databases using natural language without requiring SQL knowledge. Traditional Text-to-SQL solutions often struggle with ambiguous requests, invalid SQL generation, prompt injection, unauthorized database operations, sensitive data exposure, and inefficient repeated queries.
Built with FastAPI, LangGraph, SQLAlchemy Core, PostgreSQL, and Redis, Query Sentinel implements a 14-node workflow to address these challenges. It performs input validation and prompt-injection detection, clarifies ambiguous user intent, retrieves relevant database schema information, and uses an LLM to generate SQL queries. Generated queries undergo SQLGlot-based security checks and syntax validation before execution against a dedicated read-only database user, restricting potentially destructive operations.
The system incorporates exact and semantic caching to reduce redundant computation, LangSmith for tracing and observability, and output guardrails to detect potentially sensitive information and inappropriate responses. Its stateful workflow supports clarification and conversation continuity, allowing users to refine their requests when necessary.
Rather than treating Text-to-SQL as a simple translation task, Query Sentinel focuses on making natural-language database access safer, more reliable, and easier to monitor. The project demonstrates the integration of LLM orchestration, database security, retrieval-based caching, validation pipelines, and LLMOps practices into a practical AI backend system.