Business AI · Public case study

Text-to-SQL Business Assistant

A business analytics assistant that converts plain-English questions into guarded read-only MySQL queries and returns a clear summary, result table and downloadable output.

LLM workflow
Gemini and LangChain
Backend
FastAPI
Data layer
MySQL and SQLAlchemy
User interface
Streamlit

Why this system exists.

Business users often know the question they need answered but cannot translate it into SQL. Directly exposing an LLM to a database, however, creates risks around destructive statements, repeated API usage and unclear outputs.

Plain-English question → Streamlit or API → SQL cache lookup → Gemini and LangChain on cache miss → SELECT-only safety validation → MySQL execution → business summary, table and rows

What the public implementation demonstrates.

  • Generates MySQL SELECT statements from natural-language business questions.
  • Blocks destructive SQL keywords and rejects statements that do not begin with SELECT.
  • Caches generated SQL so repeated questions do not repeatedly consume model quota.
  • Returns a business-readable summary, tabular result and downloadable output.
  • Includes a sample relational schema, seed data, API documentation and deployment notes.

What I designed and built.

  • Application architecture and safe Text-to-SQL workflow design.
  • FastAPI backend and Streamlit interface.
  • Gemini and LangChain integration with schema-aware prompting.
  • SQL validation, caching, database execution and summary generation.
  • Sample database, documentation and production-hardening guidance.

Reliability, safety and responsible use.

Engineering decisions

  • The application separates model generation, SQL safety, database access, caching and presentation concerns.
  • A cache-first strategy reduces repeated model calls and improves quota efficiency.
  • The public example reinforces the use of a read-only database user for production environments.

Limitations

  • A public production deployment would still require authentication, rate limiting and strict CORS controls.
  • Sensitive enterprise schemas should not be sent to an external model without organisational approval.
  • A persistent cache and production-grade observability would be needed at larger scale.

The implementation stack.

Public and inspectable. The repository contains the implementation, documentation and setup guidance available for this project.
PythonGeminiLangChainFastAPIMySQLSQLAlchemyStreamlitSQL Guardrails