Self-hosted text-to-SQL for a private database
Run an open-source text-to-SQL library against your own database, trained on your schema and example queries, inside your network.
DifficultyIntermediate
Setup timeHalf a day
CategoryData & analytics
The use case
Some teams cannot send schemas or data to a hosted analytics tool. Vanna is an open-source Python library that learns from your schema, documentation and example question-SQL pairs, then generates SQL for new questions and can run it against Postgres, Snowflake, BigQuery and others. It can use a local or hosted model. A data engineer controls what it is trained on and which database user it runs as. Analysts review generated SQL, and the connection should use a read-only account.
Example workflow
- Install the library and choose a model
- Load schema, docs and example queries
- Connect with a read-only database user
- Ask questions and review SQL
- Add corrected queries as new examples
Tools
- Vanna
- PostgreSQL
Risks and guardrails
- Use a read-only user so queries cannot change data
- Example queries can teach wrong patterns
- Check where data goes if using a hosted model
Sources
Written by Agents Lookup. Credits and official pages for the tools this use case names:
- Vanna on GitHub: github.com/vanna-ai/vanna
- Vanna AI (official page): vanna.ai (checked 2026-11-19)