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.
Numbers
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.
› hover or tap a node for a one-line explanation
- Question A user sends a message in Telegram.
- Router Fixed commands go to scripted queries and free text goes to the AI handler.
- Input guardrail Destructive requests are blocked before the model sees them.
- SQL generation A local SQL model writes the query.
- Validation Checks that the SQL is read-only and uses known columns.
- Execution The query runs on ClickHouse with a read-only user.
- Formatter Small results become a table and results over 15 rows become a CSV.
- Bot reply The answer returns to the chat.
Key decisions
- 01
Four safety layers: input guardrail, SQL keyword validator, column validator and a read-only database user. The model never gets write access.
- 02
Retry with the error message, at most three times, with a slightly higher temperature each time.
- 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.