<aside> ๐Ÿ“…

Date: Friday, October 23, 2026 ยท Week 4, Day 26 ยท Type: Build Day

</aside>

Learning Manual

26.1 Enterprise Data in Databases โ€” why enterprise intelligence requires querying relational databases (PostgreSQL, SQLite), not just unstructured PDFs.

26.2 Text-to-SQL Fundamentals โ€” asking an LLM to convert a user's natural language question into a structured SQL SELECT query.

26.3 Security & Read-Only Locks โ€” preventing the model from generating destructive queries (DROP TABLE, DELETE, UPDATE) or exposing unauthorized columns.

The Daily Build

Build a safe Text-to-SQL Assistant in Python that connects to a local SQLite database, converts natural language questions into SQL, validates that the query is strictly read-only, executes the query, and formats the result.

Architecture Diagram

+--------------+     +------------------+     +--------------------+     +--------------------+
| User Query   | --> | Text-to-SQL LLM  | --> | Read-Only Validator| --> | SQLite Database    |
+--------------+     +------------------+     +--------------------+     +--------------------+
                                                       |                         |
                                            [Blocks Destructive SQL]    [Query Results Table]

Interview Questions

  1. Why is telling an LLM in its prompt "Never generate a DROP TABLE statement" completely insufficient to protect a production database?
  2. How do you provide a database schema (tables, columns, types) to an LLM without overloading its context window?
  3. What database permission settings should you configure at the database level when connecting an AI model to an enterprise database?

Problem Statement

Problem 26. Write a SQL query safety validator function is_safe_sql(query: str) -> bool in Python that inspects a raw SQL string, ensures it starts with SELECT, and returns False if it contains any forbidden keywords (DROP, DELETE, UPDATE, INSERT, ALTER, TRUNCATE, EXEC).

AI-DSA Primitive

Data Structure: SQL Token Stream / AST Validator.

Mechanics: Parsing SQL keywords into an array of normalized token strings to check for prohibited database operations.

Real-World Production Use: Deployed inside enterprise data connectors (Snowflake Cortex, Databricks AI, LangChain SQL Agent) to enforce read-only safety.

Software Design Pattern