Building a Production Text-to-SQL Assistant with Multi-Agent Architecture

linkedin · Tech · 2024 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.4 (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: Enterprise text-to-SQL assistant for data analytics

LinkedIn needed SQL Bot to help employees find data, write SQL, fix errors, and understand datasets across a massive enterprise warehouse where table metadata is incomplete, source-of-truth tables change, user questions carry implicit business context, and query correctness is hard to evaluate automatically.

Constraints:

Architecture

SQL Bot is a multi-agent LangChain/LangGraph system integrated into DARWIN. It combines intent classification, embedding-based retrieval, personalized dataset filters, dataset certification, AI-augmented metadata, DataHub deprecation signals, a knowledge graph over users/table clusters/tables/fields, LLM rerankers for table and field selection, iterative plan-based query writing, validators, and a self-correction agent. DARWIN UI elements expose tables, queries, validation checks, feedback, guided flows, and Fix with AI.

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

flowchart LR
  darwin-platform[DARWIN Platform] --> user-interface[User Interface]
  user-interface --> sql-bot[SQL Bot]
  sql-bot --> intent-classifier[Intent Classifier]
  intent-classifier --> table-retrieval[Table Retrieval]
  table-retrieval --> embedding-vector-store[Embedding Vector Store]
  table-retrieval --> personalization-layer[Personalization Layer]
  table-retrieval --> knowledge-graph[Knowledge Graph]
  embedding-vector-store --> datahub[DataHub]
  datahub --> knowledge-graph
  knowledge-graph --> llm-rerankers[LLM Rerankers]
  llm-rerankers --> query-writer[Query Writer]
  query-writer --> validators[Validators]
  validators --> self-correction-agent[Self Correction Agent]
  self-correction-agent --> table-retrieval
  access-control-layer[Access Control Layer] --> sql-bot
  personalization-layer --> access-control-layer
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
DARWIN Platform LinkedIn data science platform where users write queries and access SQL Bot. SQL Bot, User Interface
User Interface DARWIN sidebar, Fix with AI entrypoint, guided experience, rich table/query elements, feedback, and custom instructions. DARWIN Platform, SQL Bot
SQL Bot Multi-agent assistant that finds tables, writes queries, fixes errors, and handles dataset/query conversations. DARWIN Platform, Intent Classifier, Table Retrieval, Query Writer, Self Correction Agent
Intent Classifier Routes user requests to SQL writing, table finding, dataset Q&A, reference query, syntax help, or follow-up chat flows. SQL Bot, Table Retrieval
Table Retrieval Filtering and embedding-based retrieval layer that creates candidate table lists. Embedding Vector Store, Personalization Layer, Knowledge Graph
Embedding Vector Store Semantic store for table and field context, including popular queried tables and AI-augmented descriptions. Table Retrieval, DataHub
Personalization Layer Uses organizational chart and ICA over access history to infer default datasets for each user. Table Retrieval, Access Control Layer
Knowledge Graph Graph of users, table clusters, tables, fields, schemas, query logs, DataHub attributes, and crowdsourced knowledge. Table Retrieval, LLM Rerankers
LLM Rerankers LLM-based table and field rerankers that select top tables and fields for query writing. Knowledge Graph, Query Writer
Query Writer Iterative plan-and-solve query generation component with internal state across steps. LLM Rerankers, Validators, Self Correction Agent
Validators Checks table/field existence and EXPLAIN syntax before returning or correcting queries. Query Writer, Self Correction Agent
Self Correction Agent Agent that uses validation errors and extra retrieval tools to repair failed SQL. SQL Bot, Validators, Table Retrieval
DataHub Metadata search/discovery source for schemas, deprecation signals, field descriptions, top values, partitions, and classifications. Embedding Vector Store, Knowledge Graph
Access Control Layer Checks whether users belong to groups with dataset read permissions and emits group credential code where appropriate. Personalization Layer, SQL Bot

Data flow

A user asks a question in DARWIN. SQL Bot classifies the intent, retrieves candidate tables through filtering and embedding-based retrieval, personalizes defaults using org chart and access-history ICA components, reranks the top tables and fields with LLMs using knowledge-graph context, writes a query iteratively from a plan, validates table/field existence and EXPLAIN syntax, and hands errors to a self-correction agent that can retrieve additional context before updating the query.

4 supporting quotes
“SQL Bot is a multi-agent system built on top of LangChain and LangGraph.”article, stated
“We use Embedding-Based Retrieval (EBR) to retrieve context semantically relevant to the user’s question. One challenge in retrieving tables and fields is the frequent absence or incompleteness of descriptions.”article, stated
“Then, we use LLMs to filter and sort the results from EBR using the knowledge graph. After retrieving the top 20 tables via EBR, we employ a LLM re-ranker to select the top 7 tables for query writing.”article, stated
“Finally, we run a set of validators on the output followed by a self-correction agent to fix errors. Validators work best when they access new information not available to the query writer.”article, stated

Why this architecture

LinkedIn treated text-to-SQL as enterprise retrieval, ranking, and correction rather than direct NL-to-query generation. The system narrows millions of tables through popularity, personalization, EBR, and knowledge-graph reranking; writes queries iteratively for complex questions; and uses validators plus self-correction to address syntax and schema errors. Integrating into DARWIN made the assistant appear where users already write and fix SQL.

4 supporting quotes
“While creating a proof of concept for a Text-to-SQL tool is straightforward, the challenge lies in navigating complex enterprise data warehouses to identify authoritative data sources that accurately answer user questions.”article, stated
“We can quickly narrow down the volume of tables to a few thousand by looking at access popularity. However, addressing the implicit context is more subtle.”article, stated
“After retrieving the top 20 tables via EBR, we employ a LLM re-ranker to select the top 7 tables for query writing.”article, stated
“We integrated SQL Bot directly into DARWIN, allowing users to access it within the same browser window as they write and execute their queries. This integration increased adoption by 5-10x compared to our prototype chatbot application launched as a standalone app.”article, stated

Models used: LLMs · LLM rerankers · LLM-as-a-judge · embedding models

Scale

Alternatives considered (roads not taken)

Standalone prototype chatbot

Rejected because: Users adopted SQL Bot far more when it was integrated into DARWIN where they already write and execute queries.

“This integration increased adoption by 5-10x compared to our prototype chatbot application launched as a standalone app.”article, stated
“We integrated SQL Bot directly into DARWIN, allowing users to access it within the same browser window as they write and execute their queries. This integration increased adoption by 5-10x compared to our prototype chatbot application launched as a standalone app.”article, stated

Always answer with SQL

Rejected because: Users wanted table discovery, dataset questions, reference queries, syntax help, and follow-up conversations too.

“Our initial prototype answered every question with a SQL query, but users actually wanted to find tables, ask questions about the datasets, see reference queries, or ask general questions about query syntax. We now use intent classification to classify the question and decide how to respond.”article, stated
“users actually wanted to find tables, ask questions about the datasets, see reference queries, or ask general questions about query syntax.”article, stated

Use access popularity alone for table retrieval

Rejected because: Popularity narrows the space, but user questions contain implicit business context that needs personalization.

“We can quickly narrow down the volume of tables to a few thousand by looking at access popularity. However, addressing the implicit context is more subtle.”article, stated
“However, addressing the implicit context is more subtle. For instance, the question "What was the average CTR yesterday?" should be answered differently depending on whether the employee is interested in email notifications, ads or search quality.”article, stated

Run SQL queries and compare outputs for evaluation

Rejected because: LinkedIn used human and LLM-as-judge evaluation because output comparison required data access and gave less diagnostic insight.

“This approach was more practical for us than running SQL queries and comparing outputs because it does not require data access”article, stated
“This approach was more practical for us than running SQL queries and comparing outputs because it does not require data access, allows us to assess how close the query is to being correct, and gives deeper insights on how the model can be improved.”article, stated

Patterns

multi-agent-orchestration (agent-architecture)

SQL Bot delegates intent handling, table/field retrieval, query writing, follow-up chat, validation, and self-correction across agentic flows.

“SQL Bot is a multi-agent system built on top of LangChain and LangGraph.”article, stated
“The user’s question is classified and delegated to the appropriate flow.”article, stated

rag-retrieval (text-to-sql)

SQL Bot retrieves schemas, example queries, metadata, domain knowledge, and table context before query generation.

“context such as table schemas, example queries, and other domain knowledge are retrieved and passed to a Large Language Model”article, stated
“The inputs to table selection include table descriptions, example queries, domain knowledge”article, stated

retrieval-ranking (enterprise-search)

LinkedIn narrows candidates by popularity and EBR, then reranks tables and fields with LLMs over knowledge-graph context.

“LLMs to filter and sort the results from EBR using the knowledge graph.”article, stated
“We use another LLM re-ranker to select fields from the selected tables.”article, stated

agent-memory (query-planning)

Solutions to previous query-writing subtasks are stored in chatbot state and provided to later steps.

“Solutions to previous tasks are stored in our chatbot’s internal state to be provided to the next step.”article, stated

fallback-degradation (self-correction)

Validators feed syntax and schema errors into a self-correction agent that can retrieve more context before rewriting SQL.

“These errors are fed into a self-correction agent”article, stated
“equipped with tools to retrieve additional tables or fields if needed before updating the query.”article, stated

llm-as-judge (evaluation)

LinkedIn combines human evaluation with LLM-as-a-judge scoring against schemas and ground truths.

“we use a combination of human evaluation and LLM-as-a-judge to evaluate responses”article, stated
“The rubric includes overall score and dimensions on correctness in terms of tables, columns, joins, filters, aggregations”article, stated

safety-policy-enforcement (data-access)

SQL Bot checks whether users belong to groups with access and supplies group credential code when appropriate.

“Each dataset at LinkedIn has its own access control list which permits dataset read access to only specific users or groups.”article, stated
“we check if the user is a member of a group with the appropriate access”article, stated

Tradeoffs

Integrate into DARWIN

Chose same browser window as query writing/execution over standalone chatbot application.

Rationale: The integrated placement dramatically increased adoption and surfaced SQL Bot at moments of query-writing need.

“allowing users to access it within the same browser window as they write and execute their queries.”article, stated
“This integration increased adoption by 5-10x compared to our prototype chatbot application launched as a standalone app.”article, stated

Use LLM-as-judge plus human evaluation

Chose rubric scoring against question, schemas, and ground truths over executing SQL and comparing result outputs.

Rationale: Judging queries avoided data-access requirements and gave richer diagnostics on tables, joins, filters, aggregations, efficiency, and complexity.

“This approach was more practical for us than running SQL queries and comparing outputs because it does not require data access”article, stated
“gives deeper insights on how the model can be improved.”article, stated

Use guided step-by-step query writing as an option

Chose guided experience with user feedback at each step over only opaque one-shot query generation.

Rationale: Users can inspect table/query choices, understand the output, and correct the bot during query construction.

“SQL Bot walks them through each step of the query writing process—finding tables, and solving each step in the query.”article, stated
“The user can interact at each step to provide feedback on the table or queries.”article, stated

Let users customize datasets and instructions

Chose self-serve product-area configuration over platform-team-only tuning.

Rationale: LinkedIn wanted domain experts to improve SQL Bot performance without waiting on the platform team.

“We want users to have the ability to improve SQL Bot’s performance without making requests to the platform team.”article, stated
“we provide three levers that allow users to customize the experience for their product area”article, stated

Gotchas (what bit them)

Enterprise table metadata is often incomplete.

Root cause: Many tables and fields lack good descriptions, making semantic retrieval fragile.

Resolution: LinkedIn ran dataset certification and augmented descriptions with AI-generated annotations from docs and Slack.

“One challenge in retrieving tables and fields is the frequent absence or incompleteness of descriptions.”article, stated
“These descriptions were augmented with AI-generated annotations based on existing documentation and Slack discussions”article, stated

Popular-table filtering does not resolve implicit context.

Root cause: The same metric phrase means different things across product areas.

Resolution: SQL Bot infers default datasets from org structure and ICA components over access history.

“the question "What was the average CTR yesterday?" should be answered differently depending on whether the employee is interested in email notifications, ads or search quality.”article, stated
“we infer the default datasets for a user based on the organizational chart.”article, stated

Source-of-truth tables drift over time.

Root cause: Tables and fields are deprecated, added, or replaced as warehouse systems evolve.

Resolution: LinkedIn automatically ingests popular queried tables and offboards deprecated datasets/fields using DataHub signals.

“the source of truth to answer a question can change.”article, stated
“we use this signal to automatically offboard datasets and fields.”article, stated

Iterative query writing can overcomplicate simple questions.

Root cause: Plan-and-solve decomposition helps complex questions but may add unnecessary steps for simple ones.

Resolution: LinkedIn instructs the planner to minimize the number of steps it creates.

“we found it can result in overly complicated queries for simple questions”article, stated
“we instruct the query planner to minimize the number of steps it creates.”article, stated

Schema and syntax validation need information unavailable to the query writer.

Root cause: The generator may not know current table/field existence or syntax errors from the target engine.

Resolution: Validators check existence and EXPLAIN, then self-correction retrieves extra tables/fields as needed.

“Validators work best when they access new information not available to the query writer.”article, stated
“We verify the existence of tables and fields, and execute the EXPLAIN statement on the query”article, stated

Evaluation

LinkedIn built a benchmark with domain experts, measured table/field recall, hallucination rate, syntax correctness, and latency, then added human plus LLM-as-judge evaluation for deeper query-accuracy assessment.

Metrics: table recall · field recall · table hallucination rate · field hallucination rate · syntax correctness · response latency · query accuracy survey rating · LLM-as-judge rubric score · adoption lift · Fix with AI session share

3 supporting quotes
“Our evaluation metrics include recall of tables and fields compared to the ground truth, table/field hallucination rate, syntax correctness, and response latency.”article, stated
“we use a combination of human evaluation and LLM-as-a-judge to evaluate responses”article, stated
“A benchmark should preferably be tailored to the specific application”article, stated

Outcomes

LinkedIn reports millions of tables, candidate narrowing to a few thousand by access popularity, reranking from top 20 to top 7 tables, a benchmark of over 130 questions across 10 product areas, hundreds of employees using the tool, 5-10x adoption lift after DARWIN integration, and 80% of sessions using Fix with AI.

3 supporting quotes
“now utilized by hundreds of employees across LinkedIn’s diverse business verticals.”article, stated
“we’ve seen sustained adoption in the months following integration into DARWIN.”article, stated
“the “Fix with AI” feature was easy to develop but has very high usage—accounting for 80% of our sessions”article, stated