text2sql-assistant: Nexus AI Query: The Local-First Text-to-SQL Copilot That Keeps Your Schema at Home

A FastAPI, React, and Ollama stack that turns natural language into PostgreSQL queries without sending your data to a cloud model.

7-9 min read View on GitHub More from happyharsh-07

A workstation sits inside a sealed room with a PostgreSQL vault, a compact local model, and a paper schema feeding into the same enclosed system. The scene explains how the app keeps query generation and database access inside one trust boundary instead of handing the job to a remote cloud service.
The whole pitch fits in one room: schema, model, SQL, and database stay local.
Key Takeaways

Why this project exists

The problem Nexus AI Query solves is not SQL. It is trust. Teams want natural-language access to their data, but many do not want to hand schemas and query intent to a cloud model just to answer a question.

That makes this repo interesting in a very specific way. It is a privacy-first answer to a corporate AI dilemma, and it does not try to be clever about it. The model is local, the database is local, and the whole pipeline stays small enough to understand at a glance.

A tiny model, a local database, and a very short trust chain

The pipeline is short on purpose. Every step lives on the same machine, which keeps the trust chain narrow and legible.

The architecture is almost blunt in its simplicity. A user asks a question, the backend injects schema context into the prompt, Ollama generates SQL, the app strips markdown fences, and PostgreSQL executes the result locally.

That is the key idea: the model is not a distant API dependency. It sits beside the database workflow, which reduces the number of places where sensitive context can leak.

How the query pipeline actually works

A close-up of a hand passing a schema card into a small machine while another hand peels away markdown fences from a generated query strip before it reaches a database vault. The image explains the repo's most important implementation detail: raw LLM output is cleaned before execution.
The subtle part is not generation. It is cleanup. Markdown fences come off before SQL ever reaches PostgreSQL.

The most revealing line in `backend/main.py` is also the most ordinary one. The app strips away markdown wrappers before execution, because LLMs like to answer in fenced code blocks and PostgreSQL does not care about that formatting.

sql_query = raw_ai_response.replace("```sql", "").replace("```, "").strip()

That tiny cleanup step tells you a lot about the repo’s philosophy. It is not building a grand abstraction layer. It is building the shortest useful path from prompt to query.

The other notable choice is the hardcoded schema context. Instead of asking the model to discover the database from scratch, the backend supplies table names and column types up front. That improves usefulness, but it also means the system depends on careful prompt construction rather than deeper reasoning.

The frontend is doing more than looking good

The React app is not a thin wrapper around a form. It presents the system like an operations console, with status indicators, a live clock, and a polished glassmorphism layout that makes the tool feel monitored rather than casual.

That matters because interface shape changes user trust. A dashboard with visual structure suggests an internal tool that belongs in a real workflow, not a novelty demo.

The UI also gives the backend story a better frame. Instead of emphasizing chat, it emphasizes control. That makes the product feel less like a chatbot and more like a query instrument.

The fastest path is not the safest path

DimensionNexus AI QueryCloud text-to-SQL copilotManual SQL dashboard
PrivacyKeeps schema and execution localUsually sends context to a remote modelKeeps data local, but requires SQL fluency
Speed to answerFast for simple questionsFast, but depends on network and serviceFast only for experienced users
Security posturePrototype-level, with direct SQL executionDepends on vendor controls and policyStrong if users are trusted, weak if they are not
SetupSmall stack, simple mental modelOften easier to start, harder to governFamiliar, but steeper for non-SQL users
Best fitLocal, constrained, privacy-sensitive workflowsBroad enterprise adoption with external AI acceptedAnalysts and engineers who already write SQL

The comparison makes the trade-off obvious. Nexus AI Query is not the most capable option, and that is not the point. It is the most self-contained one.

That self-containment comes with a sharp edge. The backend executes AI-generated SQL directly, which is elegant for a prototype but risky in production. Prompt injection, destructive queries, and accidental misuse are all real concerns once the system leaves a trusted demo environment.

Seed data, instant demo, and prototype maturity

The `seed.py` approach is a quiet strength. By generating realistic employee records instead of shipping a static dump, the repo makes setup feel immediate and productized.

That is a good sign in a prototype. It means the author is thinking about onboarding, not just code paths. A fresh clone can become a live demo quickly, which is exactly what a local-first proof of concept should do.

The maturity level is still early. The stack is clean, the flow is understandable, and the UI is polished, but the security story is not hardened. That tension is the real story here: strong UX and honest constraints, not enterprise completeness.

What it looks like next to cloud copilots

ApproachPrivacyOperational overheadModel strengthRisk profile
Nexus AI QueryHigh, because it stays localLowGood enough for constrained SQL tasksDirect SQL execution needs guardrails
Cloud copilotsLower, because context leaves the machineMedium to highTypically stronger general reasoningGovernance and vendor dependency
Manual SQL toolsHigh, because no AI layer is involvedLow to mediumN/ARelies on human expertise

The project’s advantage is not raw intelligence. It is fit. When the main constraint is data locality, a small local model plus PostgreSQL is a strong answer.

Nexus AI Query is best read as a blueprint. It shows how far you can get with a narrow trust chain, a thin backend, and a UI that makes the result feel operational instead of experimental.