git404hub

what is text2sql fr?

abhirajthakur/text2sql — explained in plain English

Analysis updated 2026-05-18

0TypeScriptAudience · developerComplexity · 4/5Setup · hard

tl;dr

A natural-language-to-SQL tool for PostgreSQL that layers multiple safety checks to stop destructive or wrong queries before they run.

vibe map

mindmap
  root((text2sql))
    What it does
      English to SQL
      Multi layer guardrails
      Read only execution
    Tech stack
      TypeScript
      Nextjs
      Hono
      Drizzle ORM
    Guardrail layers
      Intent check
      AST policy check
      Row limit enforcement
      Read only DB role
      Result validation
    Use cases
      Natural language queries
      Safety pipeline study
      Local demo schema
    Limitations
      Fixed schema
      Single tenant
      Validation not proof

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

what do people make with this?

VIBE 1

Let non-technical users ask database questions in plain English and get safely executed SQL results.

VIBE 2

Study a worked example of layered guardrails for LLM-generated SQL, from intent checks to a read-only database role.

VIBE 3

Run the demo locally against the included customers, products, and orders schema to see the safety pipeline in action.

VIBE 4

Use the second-pass LLM validation step as a model for checking whether generated SQL actually answers the original question.

what's the stack?

TypeScriptNext.jsHonoDrizzle ORMPostgreSQL

how it stacks up fr

abhirajthakur/text2sql0xkinno/astraea0xkinno/halcyon
Stars000
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyhardhardhard
Complexity4/54/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

how do i run it?

Difficulty · hard time til it works · 1h+

Requires a Postgres database, separate admin and read-only credentials, and both a Groq and a Gemini API key.

in plain english

Text2SQL lets you ask a question about a PostgreSQL database in plain English and get back an answer, while trying hard to make sure the automatically generated SQL cannot damage the database or return a misleading result. Turning a natural language question into a database query with an AI model is easy to demonstrate but risky in practice, because even a model that works most of the time can still occasionally produce a destructive command or a confidently wrong answer. This project's approach is to add several independent safety checks rather than simply trusting the model. A question passes through several stages before it becomes a final response. First, a simple keyword check looks for destructive intent in the plain English question itself, before any AI call happens. Next, an AI model, primarily one from Groq with a Google Gemini model as a backup, generates the SQL along with an explanation and a confidence score, and this generated SQL is checked for correct syntax with one retry allowed. The SQL is then analyzed structurally to confirm it is a single read-only SELECT statement, is not accessing tables or columns outside an approved list, does not call known dangerous database functions, and has a limit on how many rows it can return. Even after all of that, the query only ever runs against a database account that has read-only permission and a time limit, so a write operation would be blocked at the database level even if every earlier check somehow failed. Finally, a second, independent AI call reviews the question, the SQL, and a sample of the results to judge whether the answer actually addresses what was asked. The project is built as a monorepo with a Cloudflare Workers backend using the Hono framework, a Next.js frontend, and a serverless Postgres database accessed through the Drizzle database toolkit. Running it locally requires installing dependencies with pnpm, setting up a database, and providing API keys for the Groq and Gemini AI services. The README notes some current limitations: it only works with one fixed demo database schema of customers, products, and orders, it is built for a single set of database credentials rather than multiple users, and the final AI-based result check is not a mathematical proof that the SQL is correct, just an added layer of scrutiny. The README does not state a license.

prompts (copy fr)

prompt 1
Help me clone text2sql and set up the DATABASE_URL, QUERY_DATABASE_URL, GROQ_API_KEY, and GEMINI_API_KEY environment variables.
prompt 2
Explain how the AST-based policy check in this project blocks stacked SQL statements and dangerous functions.
prompt 3
Walk me through why this project uses a read-only Postgres role as a final backstop even after all the earlier checks.
prompt 4
Show me how I could extend text2sql's guardrails package to support a different database schema than the demo one.

Frequently asked questions

what is text2sql fr?

A natural-language-to-SQL tool for PostgreSQL that layers multiple safety checks to stop destructive or wrong queries before they run.

What language is text2sql written in?

Mainly TypeScript. The stack also includes TypeScript, Next.js, Hono.

How hard is text2sql to set up?

Setup difficulty is rated hard, with roughly 1h+ to a first successful run.

Who is text2sql for?

Mainly developer.

peek the repo → explain another one

This repo across BitVibe Labs

double-check against the repo, no cap.