×
Case Studies Blog Careers Technologies
Text-to-SQL with Gen AI: Opportunities, Limits, and the Enterprise Reality

Recently we engaged with a leading prospect who asked a simple but powerful question: “Can Gen AI solve the text-to-SQL problem for our analysts, and will this make BI platforms obsolete?”

Generative AI has made text-to-SQL one of the hottest areas in enterprise analytics. Business users can now query databases with plain language instead of writing complex SQL. Early demos look magical - but the enterprise reality is much harder.

Most organizations don’t just have clean tables. They have ambiguous business terms, hidden logic in stored procedures, data spread across systems, and decades of BI governance. This blog explores:

  • What Gen AI can and cannot solve in text-to-SQL ?
  • How graph databases help bridge the gap ?
  • Why BI platforms won’t disappear ?
  • The hidden challenge of stored procedures.
  • A roadmap for modernization.

1) What Gen AI Can Solve in Text-to-SQL. At its best, Gen AI + SQL works when:

  • Schema is small and clear.
  • User intent maps directly to columns/tables.
  • Query involves simple filters, joins, and aggregations.

Examples:

  • “List all customers in Mumbai.”
  • “Show orders above ₹10,000 in March 2025.”
  • “Top 10 products by sales.”

In these cases, text-to-SQL works well with little additional support.

2) Where Gen AI Fails - Despite progress, Gen AI struggles with:

  • Ambiguous terms (“top performers” = salespeople? products?).
  • Complex joins across multiple tables.
  • Business rules (e.g., “active customer” definition).
  • External or missing data (e.g., inflation-adjusted metrics).
  • Performance optimization - valid SQL may still run slowly.
  • Compliance/security - AI may generate queries that expose restricted data.

3) Adding Graph DB to the Mix. A promising solution is combining graph data models with Gen AI.

  • Ontology mapping: “Performer” → SalesRep entity.
  • Join discovery: Graph knows Orders → Customers → Region.
  • Business rules: “Active Customer” = stored as graph rule referencing DB columns.
  • Synonyms: “Churned” → status='Inactive'.
  • Role-based access: Graph encodes who can query what.

Workflow:

  1. NL query → parsed by LLM.
  2. Graph DB resolves entities, joins, business rules.
  3. AI generates SQL grounded in graph.
  4. Query executed in RDBMS.

This reduces ambiguity and hallucinations dramatically.

4) What Still Cannot Be Solved (Even with Graph + Gen AI)

  • Missing/external data (inflation index, competitor prices).
  • Subjective intent (“best customer” = by revenue, profit, tenure?).
  • Dirty data issues (duplicates, nulls, timezone mismatches).
  • Advanced analytics (churn forecasting, anomaly detection → need ML).
  • Query performance tuning (execution plans, indexes still human-driven).
  • Compliance nuances (e.g., subtle GDPR restrictions).

5) Will This Replace BI Platforms? Short answer: No. BI platforms (Tableau, Power BI, Looker) provide:

  • Visualization → dashboards, charts, drill-downs.
  • Governance → data lineage, RBAC, compliance logging.
  • Data prep & caching → optimized query layers.

Gen AI generates SQL, but it does not replace governance, storytelling, or performance management. Likely outcome: AI-augmented BI.

  • BI tools embed Gen AI → conversational querying.
  • AI suggests insights → “Revenue in Asia dropped 8% QoQ, driven by India.”
  • Users interact via chat instead of rigid dashboards.

6) The Stored Procedure Challenge : Most enterprises have decades of business logic encoded in stored procedures (SPs).

  • Problem: Text-to-SQL bypasses SPs, producing inconsistent results.
  • Example: AI’s SUM(sales) vs. SP’s revenue logic (FX adjustments, cancellations).
  • Discoverability: Thousands of undocumented SPs, often vendor-specific (T-SQL, PL/SQL).
  • Execution gap: Sometimes the right query is not SQL, but EXEC GetQuarterlyRevenue.

Gen AI must learn when to generate SQL vs. when to invoke SPs. Strategies for Stored Procedures in AI Era

  1. Expose SPs via metadata/service catalog → AI can discover and call them.
  2. Graph ontology → map business terms to SPs (e.g., “Active Customer” → GetActiveCustomers).
  3. Parse & embed SPs → index them in a vector DB for retrieval.
  4. Gradually refactor SP logic → into semantic/metric layers (dbt, LookML, Cube.js).

7) Roadmap for Enterprises

Phase 1: Today (SP-heavy)

  • SPs dominate business logic.
  • Wrap key SPs with metadata for AI discoverability.

Phase 2: Near-Term

  • Introduce graph/semantic layers.
  • Train AI orchestration to decide between SQL generation vs. SP execution.

Phase 3: Long-Term

  • Refactor SP logic into semantic/metric layers.
  • SPs shrink to edge cases.
  • Enterprise logic becomes transparent, governed, and AI-friendly.

Conclusion : Gen AI for text-to-SQL is a leap forward, but enterprise adoption requires more than prompt-to-query magic.

  • Graph DBs reduce ambiguity and ground AI in schema + business semantics.
  • BI platforms remain essential for governance, visualization, and performance.
  • Stored procedures are the elephant in the room - they won’t vanish, but AI will expose their opacity and drive modernization.

The future is AI-augmented BI with semantic layers, not AI replacing BI.

Enterprises that modernize SP-heavy ecosystems into graph + semantic models will be the ones to unlock true Gen AI analytics.

Text-to-SQL is not just an application; it is the catalyst for total data transformation. By forcing us to clean our metadata, harden our security, and refine our semantic definitions, it paves the way for a truly data-driven organization. The question is no longer if you will use it, but how quickly you will lay the foundational pipes to harness its power.

What aspects of Opportunities or Limits are you most interested in discussing further?