Zing Forum

Reading

Semantic Insights Agent: Intelligent Conversion from Natural Language to SQL Using Semantic Layer and LangGraph

An enterprise-level semantic analysis prototype that converts natural language business questions into governed SQL queries using semantic layer, LangGraph orchestration, PostgreSQL, and LLM.

语义层自然语言转SQLLangGraph数据分析PostgreSQLStreamlit数据治理LLM应用企业智能Text-to-SQL
Published 2026-06-04 21:11Recent activity 2026-06-04 21:20Estimated read 5 min
Semantic Insights Agent: Intelligent Conversion from Natural Language to SQL Using Semantic Layer and LangGraph
1

Section 01

Introduction / Main Floor: Semantic Insights Agent: Intelligent Conversion from Natural Language to SQL Using Semantic Layer and LangGraph

An enterprise-level semantic analysis prototype that converts natural language business questions into governed SQL queries using semantic layer, LangGraph orchestration, PostgreSQL, and LLM.

3

Section 03

Project Background: Technical Challenges of Data Democratization

In the field of enterprise data analysis, a long-standing contradiction exists: business personnel need data insights, but the technical threshold of SQL queries deters most people. Traditional solutions are BI tools or predefined reports, but these often fail to meet flexible and changing business needs.

hmandadi's Semantic Insights Agent attempts to bridge this gap using AI technology. It is not a simple "text-to-SQL" tool, but an enterprise-level semantic analysis system that emphasizes governance, interpretability, and architectural rigor.


4

Section 04

Core Concept: What is a Semantic Layer?

The Semantic Layer is the core innovation of this project. It sits between the original database and business users, defining:

  • Business Concepts: Mapping technical table names and field names to business terms
  • Governance Rules: Defining who can access what data and how to calculate metrics
  • Standardized Metrics: Ensuring consistent KPI definitions across the entire company

The value of this design is that when a business person asks "What was the sales volume in the East China region last quarter?", the system not only knows which table to query but also understands how "sales volume" should be calculated and which provinces are included in "East China region".


5

Section 05

System Architecture: Five-Layer Collaborative Design

The project's architectural design reflects a clear layered approach:

6

Section 06

Layer 1: Streamlit User Interface

A lightweight web interface that allows users to input questions in natural language and view results. This choice reflects the MVP (Minimum Viable Product) design philosophy—avoiding excessive resource investment in UI development before verifying core concepts.

7

Section 07

Layer 2: LangGraph Workflow Orchestration

This is the "brain" of the system. LangGraph is responsible for orchestrating LLM-driven reasoning steps, breaking down the complex natural language to SQL conversion process into manageable nodes:

  • Intent Understanding Node: Parses the user's real needs
  • Semantic Mapping Node: Maps business terms to the data model
  • SQL Generation Node: Constructs executable query statements
  • Result Validation Node: Checks the rationality and security of the query
8

Section 08

Layer 3: LLM Inference Engine (OpenAI)

Uses OpenAI's models for natural language to SQL translation. The project uses carefully designed prompt templates (prompts.py) to guide the model to generate high-quality SQL that meets enterprise governance requirements.