How I Built a Production AI Query Engine on 28 Tables — And Why I Used Both Text-to-SQL and Function Calling
A real production system running on an affiliate marketing ERP — not a demo. The Problem The operations team at an affiliate marketing company I worked with hit a classic wall. They had all the dat...

Source: DEV Community
A real production system running on an affiliate marketing ERP — not a demo. The Problem The operations team at an affiliate marketing company I worked with hit a classic wall. They had all the data: Revenue by affiliate Fraud flags Campaign ROI Conversion rates by traffic source All of it live in a 28-table MySQL database. But every non-trivial question required SQL. And the people asking the questions weren’t the ones who could write it. The goal: Let a non-technical operator ask a question in plain English and get a real answer instantly. No dashboards. No SQL. No waiting for a dev. Mistake #1 — I Started with Function Calling On paper, it looks perfect: Structured JSON Controlled schema Safe execution Then I tried a real query: “Compare campaign ROI this month vs last month, by traffic source, excluding fraud flags, grouped by affiliate tier” The schema needed: 15+ nested parameters Time comparison logic Multi-table joins The LLM hallucinated fields. The result was garbage. Reality