Building Production-Grade Conversational Analytics with LangGraph and Waii

waii · Tech · 2024 · source Agentic: yes · promotional bias: high · source-backed · extracted with prompt 0.5.5 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Conversational analytics and text-to-SQL for complex enterprise databases

Waii wanted a LangGraph-based conversational analytics application that lets users ask natural-language questions over complex database schemas while still generating accurate SQL joins, visualizations, follow-up conversations, security-constrained execution, and optimized queries.

Constraints:

Architecture

The application wraps Waii's text-to-SQL, query execution, and chart-generation APIs inside a LangGraph state machine. A question classifier decides whether a request needs database access, visualization, or a general LLM response. Database questions flow to Waii's SQL generator, which relies on a continuously refined database knowledge graph, join-path analysis, join-condition refinement, and a compiler/optimizer. The SQL executor applies security constraints and returns rows; a result classifier chooses data or chart presentation; a synthesizer returns the answer and loops back into the stateful conversation.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  user-question["User question"] --> langgraph-state["LangGraph state"]
  langgraph-state --> question-classifier["Question Classifier"]
  waii-catalog-context["Waii catalog context"] --> question-classifier
  question-classifier --> waii-sql-generator["Waii SQL Generator"]
  question-classifier --> insight-generator["Insight Generator"]
  waii-knowledge-graph["Waii knowledge graph"] --> join-graph-analyzer["Join Graph Analyzer"]
  join-graph-analyzer --> waii-sql-generator
  waii-sql-generator --> compiler-and-optimizer["Compiler and Optimizer"]
  compiler-and-optimizer --> security-constraints["Security Constraints"]
  security-constraints --> waii-sql-executor["Waii SQL Executor"]
  waii-sql-executor --> result-classifier["Result Classifier"]
  result-classifier --> waii-chart-generator["Waii Chart Generator"]
  result-classifier --> result-synthesizer["Result Synthesizer"]
  waii-chart-generator --> result-synthesizer
  insight-generator --> result-synthesizer
  result-synthesizer --> langgraph-state
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
User question Natural-language analytics request that starts each workflow iteration. LangGraph state
LangGraph state Pydantic-backed state object holding database description, query, generated SQL, rows, chart specification, insight text, response, error, and routing decision. Question Classifier
Question Classifier LLM classifier that uses Waii catalog information to route the user question to database, visualization, or general-response paths. Waii catalog context, Waii SQL Generator, Insight Generator
Waii catalog context Database catalog and schema context fetched from Waii and supplied to the question classifier. Question Classifier
Waii knowledge graph Continuously refined relationship graph over schema information, constraints, column/data-pattern predictions, query history, documentation, catalog relationships, and feedback. Join Graph Analyzer
Join Graph Analyzer Agentic flow that proposes, evaluates, and refines table paths and join conditions before query construction. Waii SQL Generator
Waii SQL Generator Text-to-SQL service that converts the user request into SQL using Waii query-generation APIs and join-planning internals. Compiler and Optimizer
Compiler and Optimizer Compilation layer that checks syntactic correctness, optimizes performance, and enforces operational query constraints such as row and partition limits. Security Constraints
Security Constraints Execution-time policy layer that injects user-level row and column restrictions into generated database access. Waii SQL Executor
Waii SQL Executor Query execution API that runs generated SQL against the database and returns rows for downstream presentation. Result Classifier
Result Classifier LLM classifier that decides whether returned results should be presented directly as data or passed to chart generation. Waii Chart Generator, Result Synthesizer
Waii Chart Generator Visualization service that generates chart specifications from query result data and metadata. Result Synthesizer
Insight Generator General LLM path for questions that the classifier decides do not require database access. Result Synthesizer
Result Synthesizer Final response step that combines query results, generated charts, or general insights into an answer and returns control to the conversational loop. LangGraph state

Data flow

A user question enters the LangGraph workflow state. The question classifier fetches Waii catalog context and classifies the request as database, visualization, or general. Database requests go to Waii Query.generate, whose table-selection and join-analysis flows use schema, constraints, query history, documentation, catalog relationships, and feedback. The compiler/optimizer checks SQL syntax, performance, and operational limits. The executor injects row/column security constraints and runs the query. A result classifier chooses data or visualization, Waii can generate charts from returned data, and the result synthesizer produces a response before the workflow loops for the next turn. On errors, LangGraph can rewrite and regenerate objects.

6 supporting quotes
“Waii](https://www.waii.ai/) provides text-to-SQL and text-to-chart capabilities, enabling natural language interactions with databases and data visualization.”article, stated
“An LangGraph Question Classifier decides if the request is best answered from memory or from database 3. [optional] The Waii SQL Generator creates an optimized SQL query. 4. [optional] The Waii SQL Executor injects security constraints, executes the”article, stated
“Classifier decides if the request is best answered from memory or from database 3. [optional] The Waii SQL Generator creates an optimized SQL query. 4. [optional] The Waii SQL Executor injects security constraints, executes the query, and retrieves results. 5. [optional]”article, stated
“The Waii SQL Executor injects security constraints, executes the query, and retrieves results. 5. [optional] A Result classifier decides if the output should be data or visualization. 6. [optional] The Waii Chart Generator creates relevant charts from”article, stated
“A Result classifier decides if the output should be data or visualization. 6. [optional] The Waii Chart Generator creates relevant charts from the data and metadata. 7. A LangGraph Insight Generation Agent synthesizes the final results for the user 8. The loop repeats. (Optional / not”article, stated
“On error or exception, LangGraph loops, rewrites input and regenerates the required objects.) Throughout this process, the Conversation Management Agent maintains state, allowing for contextual follow-up questions and a more natural, flowing interaction. The”article, stated

Why this architecture

The architecture separates workflow control from domain-specific SQL generation. LangGraph supplies stateful routing, loops, and multi-node orchestration, while Waii supplies specialized text-to-SQL, join planning, execution, and visualization capabilities. This is appropriate because the hardest part of the case is not generic conversation but accurate database relationship handling across complex schemas and join types.

4 supporting quotes
“LangGraph is a framework for building stateful, multi-agent applications using language models. Waii provides text-to-SQL and text-to-chart capabilities, enabling natural language interactions with databases and data visualization.”article, stated
“For any LangGraph application needing precise, thoughtful database access, Waii is a great addition. Integrating Waii with LangGraph allows developers to create systems that execute complex queries while maintaining context across interactions, boosting the”article, stated
“many of today’s solutions struggle with. We will examine an example, see how the joins are constructed, and explain how you can easily integrate Waii into your existing LangGraph application”article, stated
“Throughout this process, the Conversation Management Agent maintains state, allowing for contextual follow-up questions and a more natural, flowing interaction.”article, stated

Models used: OpenAI ChatGPT via ChatOpenAI · Waii text-to-SQL engine · Waii text-to-chart engine · LangGraph state machine

Scale

Alternatives considered (roads not taken)

Use a generic LLM to write SQL from natural language without a specialized database relationship layer.

Rejected because: The article argues complex joins require table selection, join graph analysis, join-condition refinement, and compilation/optimization rather than only prompting a model.

“With the knowledge graph in place, Waii employs a sequence of agentic flows to construct the optimal query: 1. Table Selection: Analyzing the user’s request to identify the most relevant tables. Common join relationships and understanding of the”article, stated
“get updates from this writer. Remember me for faster sign in 2. Join Graph Analysis: Proposing and evaluating potential join paths between selected tables. This includes scoring how well the join graph is aligned with previously seen joins and the semantic understanding of the”article, stated

Rely only on direct semantic matches between the user question and table names.

Rejected because: Waii uses relationship semantics and common join paths to find tables that may not be directly mentioned or semantically linked in the user input.

“Common join relationships and understanding of the semantics of the relationships are used to find tables and paths that might not be directly semantically linked to the user input.”article, stated

Present all SQL results as raw data.

Rejected because: The application classifies whether the result should be presented as data or a visualization and can call Waii chart generation when a chart is more appropriate.

“the query, and retrieves results. 5. [optional] A Result classifier decides if the output should be data or visualization. 6. [optional] The Waii Chart Generator creates relevant charts from the data and metadata. 7. A LangGraph Insight Generation Agent synthesizes the final results”article, stated
“A Result classifier decides if the output should be data or visualization. 6. [optional] The Waii Chart Generator creates relevant charts from the data and metadata. 7. A LangGraph Insight Generation Agent synthesizes the final results for the user 8. The loop repeats. (Optional / not”article, stated

Treat execution as a direct run of generated SQL.

Rejected because: The design inserts security constraints and operational limits around execution, so generation and execution are not a single unconstrained step.

“Code is injected to enforce user-level security policies such as limiting row / column access. 5. State Management: To maintain context across multiple user interactions, allowing for follow-up questions and iterative analysis. The flow of a typical”article, stated
“We also enforce operational constraints placed by the user on the query (e.g., max output rows, max input partitions).”article, stated

Patterns

tool-use-orchestration (architecture)

LangGraph routes each conversation turn across classifiers, Waii SQL generation, Waii execution, Waii charting, and LLM synthesis rather than relying on one monolithic prompt.

3 supporting quotes
“## Implementation Details Implementing this system involves several key components: 1. LangGraph Framework: Provides the overall structure for the multi-agent system, managing state and agent interactions.”article, stated
“[optional] The Waii SQL Generator creates an optimized SQL query. 4. [optional] The Waii SQL Executor injects security constraints, executes the query, and retrieves results.”article, stated
“The Waii Chart Generator creates relevant charts from the data and metadata.”article, stated

prompt-chaining (architecture)

The workflow chains a question-classification prompt, SQL generation, result classification, optional chart generation, insight generation, and final synthesis.

3 supporting quotes
“User inputs a question. 2. An LangGraph Question Classifier decides if the request is best answered from memory or from database 3.”article, stated
“A LangGraph Insight Generation Agent synthesizes the final results for the user”article, stated
“The loop repeats. (Optional / not shown in image: On error or exception, LangGraph loops, rewrites input and regenerates the required objects.”article, stated

query-rewriting (reliability)

On errors or exceptions, the LangGraph loop can rewrite the input and regenerate the required SQL/chart objects.

“On error or exception, LangGraph loops, rewrites input and regenerates the required objects.”article, stated

guardrails-io-filtering (safety)

The query execution path injects row and column access policies and enforces operational limits before running generated SQL.

“Code is injected to enforce user-level security policies such as limiting row / column access.”article, stated
“We also enforce operational constraints placed by the user on the query (e.g., max output rows, max input partitions).”article, stated

data-quality-loop (operations)

The database relationship graph is updated from schema changes, query history, documentation, catalog relationships, and feedback from system usage.

“Constraints (e.g., primary keys / foreign keys) * Predictions based on analyzing column names and data patterns * Join graphs extracted and ranked from query history * Database documentation * Relationships defined in data catalogs * Feedback from system usage over time This graph is”article, stated
“This graph is continuously updated and refined. Every schema change, new query, and new piece of feedback is analyzed and integrated into the graph.”article, stated

Tradeoffs

Use specialized Waii SQL services inside LangGraph rather than asking a generic LLM to own the full analytics path.

Chose LangGraph orchestration plus Waii text-to-SQL/text-to-chart APIs over A single generic LLM prompt that classifies, writes SQL, executes, visualizes, and answers.

Rationale: The article's core risk is complex database join correctness, so a specialized relationship graph, join planning, compiler, and execution layer are a better fit than a generic one-shot prompt.

“Waii](http://www.waii.ai/) offers a comprehensive text-to-SQL solution that stands out in several key areas:”article, stated
“several key areas: * High-accuracy joins across complex schemas * Scalable table selection for large databases * Bespoke compiler for syntactic correctness and query optimization * Specialized agentic flows for filters, sort order, common metrics, etc In the following section, we’ll take a deep”article, stated

Represent database relationships as a continuously refined knowledge graph.

Chose A graph fed by schema, constraints, predictions, query history, documentation, catalogs, and feedback over Static schema-only metadata.

Rationale: The graph lets Waii reason about implicit relationships, historical joins, and feedback over time, which is necessary for paths not directly obvious from the user's words.

“Waii automatically builds a comprehensive knowledge graph of the database objects.”article, stated
“This graph is continuously updated and refined. Every schema change, new query, and new piece of feedback is analyzed and integrated into the graph.”article, stated

Split query generation into agentic subflows.

Chose Table selection, join graph analysis, join-condition refinement, query construction, and compilation/optimization over One undifferentiated SQL-generation step.

Rationale: Separating these steps makes it possible to reason about table relevance, join paths, outer join conditions, syntax, optimization, and operational limits independently.

3 supporting quotes
“With the knowledge graph in place, Waii employs a sequence of agentic flows to construct the optimal query:”article, stated
“Separate check to make sure outer joins and join conditions are applied correctly.”article, stated
“Ensuring the joins are syntactically correct and optimized for performance.”article, stated

Route returned results through a visualization decision.

Chose A result classifier that chooses data or chart generation over Always returning tables of rows.

Rationale: Conversational analytics users may need visual insight rather than raw rows, so the workflow branches to chart generation when the answer is better expressed visually.

“Result classifier decides if the output should be data or visualization.”article, stated
“Visual Insights: Automatic generation of relevant visualizations enhances understanding of the data.”article, stated

Keep security and operational constraints in the execution path.

Chose Injected user-level policies and max row/partition constraints over Trusting the generated SQL text alone.

Rationale: Even if generated SQL is syntactically correct, the runtime still needs governance and resource limits before executing against real databases.

“Code is injected to enforce user-level security policies such as limiting row / column access.”article, stated
“We also enforce operational constraints placed by the user on the query (e.g., max output rows, max input partitions).”article, stated

Gotchas (what bit them)

Complex text-to-SQL fails if join semantics are treated as a shallow table-name matching problem.

Root cause: Many business questions require bridge tables, dimension tables, full outer joins, optional left joins, and chains between distant entities.

Resolution: Build and refine a database relationship graph, then run table selection, join graph analysis, join-condition refinement, query construction, and compilation as separate flows.

3 supporting quotes
“## Query analysis This query showcases a number of complex join capabilities: 1. Complex Join Graph: 14 tables used in the query with different qualifiers, arity and semantics.”article, stated
“Bridge Table Joins: Used to connect entities in many-to-many relationships”article, stated
“Separate check to make sure outer joins and join conditions are applied correctly.”article, stated

Outer joins can silently become wrong if conditions are placed in the wrong clause.

Root cause: Outer join logic depends on subtle differences between ON and WHERE conditions, especially when optional data is involved.

Resolution: Use a dedicated join-condition evaluation/refinement step that checks outer joins and ON-vs-WHERE behavior.

“This is where we also look at “on” vs “where” clause conditions for outer joins.”article, stated
“Left Joins for Optional Data: Applied when including data that might not exist for all directors”article, stated

Conversational analytics needs state, not just one-shot SQL generation.

Root cause: Users ask follow-up questions and iterative analytic requests that depend on prior context.

Resolution: Keep a LangGraph state object and conversation-management loop across query, SQL, data, chart, insight, response, error, and routing fields.

“5. State Management: To maintain context across multiple user interactions, allowing for follow-up questions and iterative analysis.”article, stated
“Throughout this process, the Conversation Management Agent maintains state, allowing for contextual follow-up questions and a more natural, flowing interaction.”article, stated

Generated SQL can bypass governance if execution security is bolted on too late.

Root cause: A natural-language SQL workflow can produce queries whose row and column access must still respect user-level policies.

Resolution: Inject user-level row/column access constraints into the Waii execution API and enforce operational query limits.

“To execute the generated SQL queries against the actual database. Code is injected to enforce user-level security policies such as limiting row / column access.”article, stated
“We also enforce operational constraints placed by the user on the query (e.g., max output rows, max input partitions).”article, stated

The case study's accuracy claims should not be treated as independent production evidence.

Root cause: The article is vendor-authored and presents a single successful complex query without comparative benchmarks or failure-rate measurements.

Resolution: Use the architecture and concrete query mechanics, but treat claims such as high accuracy and scalability as promotional unless independently evaluated.

3 supporting quotes
“Waii offers a comprehensive text-to-SQL solution that stands out in several key areas: * High-accuracy joins across complex schemas * Scalable table selection for large databases * Bespoke compiler for syntactic correctness and query optimization * Specialized agentic”article, stated
“comprehensive text-to-SQL solution that stands out in several key areas: * High-accuracy joins across complex schemas * Scalable table selection for large databases * Bespoke compiler for syntactic correctness and query optimization * Specialized agentic flows for filters, sort order, common”article, stated
“The full query generated by Waii from these instructions can be found in Appendix A.”article, stated

Evaluation

The article evaluates by walking through a complex director-performance query and implementation code rather than reporting an independent benchmark. The observable checks are structural: 14-table join coverage, bridge/dimension/full-outer/left join handling, syntactic compilation, optimization, operational constraints, security injection, and visualization routing.

Metrics: 14 tables used in the example SQL query · Top 5 directors by title count in the example request · Coverage of bridge table joins, dimension joins, complex join chains, full outer joins, and left joins for optional data · Syntactic correctness and query optimization through a compiler · Operational constraints such as maximum output rows and maximum input partitions · Row and column access security injection at execution time · Routing accuracy between database, visualization, and general-answer paths · Ability to loop, rewrite, and regenerate on errors or exceptions

5 supporting quotes
“Complex Join Graph: 14 tables used in the query with different qualifiers, arity and semantics.”article, stated
“Full Outer Joins: Employed to combine a director’s work across both movies and TV series, ensuring comprehensive coverage.”article, stated
“4. Compilation and Optimization: Ensuring the joins are syntactically correct and optimized for performance.”article, stated
“We also enforce operational constraints placed by the user on the query (e.g., max output rows, max input partitions).”article, stated
“On error or exception, LangGraph loops, rewrites input and regenerates the required objects.”article, stated

Outcomes

The concrete scale evidence is the 14-table example query, top-5 director request, large-database table-selection claim, and operational row/partition constraints. The article does not report latency, accuracy, usage volume, cost, or production adoption numbers.

5 supporting quotes
“The result is a SQL query that not only answers the user’s question accurately but does so in a way that’s optimized for the specific database structure and query engine.”article, stated
“The generated SQL uses Common Table Expressions (CTEs) extensively, with named subqueries like director_movie_count, director_tv_count, combined_counts, ranked_directors”summary, stated
“Accessibility: Complex data analysis becomes accessible to non-technical users through natural language interaction.”article, stated
“Contextual Understanding: Maintained state allows for more natural, context-aware conversations about data.”article, stated
“The article provides no quantitative benchmarks comparing Waii's accuracy to other text-to-SQL solutions.”summary, stated