Al Bunch

AINLQ — Natural Language Query System

A web application that translates plain English questions into SQL queries, executes them, and renders the results as interactive charts — automatically selecting the best visualization type. Ships with 5 industry datasets (Restaurant, Ecommerce, SaaS, HR, Auto Repair) so users can explore a domain close to their own business.

The novel contribution — #[AiSafe] attribute pattern: The biggest risk in connecting an LLM to your database isn’t SQL injection (parameterized queries handle that). It’s schema exposure — the AI needs to see your table structure to write SQL, but dumping the full schema exposes passwords, tokens, PII, and internal fields in the prompt. The #[AiSafe] PHP attribute solves this: only fields explicitly marked with the attribute are visible to the AI. Unmarked fields don’t exist as far as the LLM is concerned. It’s opt-in exposure, not opt-out hiding — the safe default is invisible.

The full pipeline:

  1. User picks an industry dataset and types a question in plain English
  2. Schema extraction dynamically reads Doctrine entity metadata, filtering to only #[AiSafe] fields
  3. Schema + question are sent to GPT-4o-mini with prompt engineering that enforces column naming conventions per visualization type (so results map cleanly to ECharts)
  4. Response is sanitized (handles markdown fences, various GPT response formats) and parsed as JSON
  5. Chart type is validated against a server-side whitelist (6 allowed types)
  6. Parameterized SQL executes via Doctrine (no raw string concatenation)
  7. Results render as bar, line, pie, gauge, KPI metric, or data table — with the generated SQL displayed below for full transparency

Architecture highlights:

Tech stack: Symfony 7.2, PHP 8.2+, Doctrine ORM 3.3, OpenAI GPT-4o-mini, ECharts, Bootstrap 5, Docker, Apache.