Next-generation Text-to-SQL: how a multi-agent system solves the task

Alexey Chudinov13 Nov 2025

Problem

Text-to-SQL assistants open data to many users. A single LLM can invent tables, misread the question, run dangerous statements or expose personal data. Corporate systems also need an audit trail.

Example from the article: for "Show the oldest clients with an overdue of more than 90 days", a plain LLM guesses a nonexistent users table and treats "oldest clients" as age > 30.

Solution in brief

The pipeline gives each concern to a separate agent: an input guard, intent extraction, schema retrieval over a vector database, SQL generation, SQL verification and audited execution. A failed verification sends the query back to the generator. The article reports no accuracy measurements.

Questions this case answers
  • How to let non-technical users query a sensitive database in natural language when the model may hallucinate tables and emit unsafe statements
  • How to structure an LLM pipeline so that input checks, context retrieval, generation, verification and audited execution are separate, replaceable components
  • How to let employees query company data in natural language without executing hallucinated or dangerous SQL?
  • How to split a text-to-SQL pipeline into specialized agents for input security, schema retrieval, generation, verification and audited execution?

Tools and methods

  • Input-Guard-Agent — blocks prompt injection, personal data and off-policy topics before other agents see the request
  • NLU-Agent — extracts intent and entities into a structured request
  • Schema-RAG-Agent — semantic search over embeddings of the schema and successful past queries
  • SQL-Generator-Agent — a specialized LLM (SQLCoder-style) prompted with the retrieved context
  • SQL-Verifier-Agent — safety check and dry-run cost estimate before execution
  • DB-Audit-Agent — executes the query, masks personal data, writes an encrypted operation log
Continue reading — it's free

Google or a one-time email code. No password.