← all projects

kevin@portfolio:~$ cat projects/executive-data-assistant.md

# AI Engineering · Text-to-SQL

Executive Data Assistant

A Telegram assistant that turns business questions in Bahasa Indonesia into read-only SQL and returns the results.

Timeframe
2025–2026
Status
NDA, architecture shown, code private
Stack
PythonFastAPIClickHouseLocal LLM runtimeTelegram Bot APISQLYAML

Numbers

100%
Query execution success on hard-level test cases

Problem

Managers wanted business numbers without asking an analyst or writing SQL. They asked in Bahasa Indonesia from a chat app.

How it works

A question first passes an input guardrail. A local SQL-specialised language model writes the query, and validators check that it is read-only and uses known columns. If a check or the database fails, the error goes back to the model for up to three attempts. Fixed commands run pre-written queries, and long results are sent as a CSV file.

QuestionRouterInput guardrailSQL generationValidationExecutionFormatterBot replyQuestionRouterInput guardrailSQL generationValidationExecutionFormatterBot reply
  1. Question A user sends a message in Telegram.
  2. Router Fixed commands go to scripted queries and free text goes to the AI handler.
  3. Input guardrail Destructive requests are blocked before the model sees them.
  4. SQL generation A local SQL model writes the query.
  5. Validation Checks that the SQL is read-only and uses known columns.
  6. Execution The query runs on ClickHouse with a read-only user.
  7. Formatter Small results become a table and results over 15 rows become a CSV.
  8. Bot reply The answer returns to the chat.

Key decisions

  1. 01

    Four safety layers: input guardrail, SQL keyword validator, column validator and a read-only database user. The model never gets write access.

  2. 02

    Retry with the error message, at most three times, with a slightly higher temperature each time.

  3. 03

    Pre-written commands for common reports, so frequent questions do not depend on the model.

Results

  • 100% query execution success on hard-level test cases.
  • A case counts as passed when the generated SQL runs without error after the retries. The two test suites hold 5 and 3 hard-level questions.