{"slug": "how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi", "title": "How Uber Scaled Text-to-SQL to 1.2M Monthly Queries: Inside QueryGPT's Multi-Agent Architecture", "summary": "Uber detailed how it evolved QueryGPT, a 2023 hackathon prototype, through 20+ iterations into a multi-agent text-to-SQL pipeline serving roughly 1.2 million interactive queries per month and cutting average query authoring time from about 10 minutes to about 3. The system replaces single-pass RAG with a progressive filtering funnel—an Intent Agent routing prompts across 12 curated System Workspaces, a Table Agent with a human-in-the-loop checkpoint, a Column Prune Agent, and a final SQL generation step—after naive retrieval broke down on wide tables exceeding 200 columns and 40K–60K tokens each.", "body_md": "Most Text-to-SQL demos look impressive on a 5-table toy database and fall apart the moment they meet an enterprise data warehouse. The bottleneck isn't SQL syntax—it's **context bloat, ambiguous domain boundaries, and tribal schema knowledge**.\n\nIn their engineering deep dive, [*QueryGPT – Natural Language to SQL Using Generative AI*](https://www.uber.com/in/en/blog/query-gpt/), Uber shared how they evolved a 2023 hackathon prototype through 20+ iterations into a production system serving **~1.2 million interactive queries per month** (with Operations alone driving ~36% of volume), cutting average query authoring time from **~10 minutes down to ~3 minutes**.\n\nHere is an architectural breakdown of why naive RAG failed at Uber's scale—and the multi-agent pipeline they built to fix it.\n\n## \n  \n  \n  1. Why V1 Naive RAG Collapsed at Scale\n\nUber's initial May 2023 prototype (*Hackdayz V1*) followed a classic single-pass RAG pattern:\n\n1. Embed the user's natural language prompt.\n2. Run k-nearest neighbor (k-NN) similarity search across a small pool of **7 Tier-1 tables** and**20 sample SQL queries** .\n3. Retrieve the **top 3 tables** and**top 7 SQL samples** , combine them with custom Uber business instructions (such as date formatting rules), and generate SQL in one LLM call.\n\n``` php\nflowchart LR\n    P[\"User Natural Language Prompt\"] --> E[\"Vector Embedding + k-NN Search\"]\n    E --> R1[\"Top 3 Table DDLs\"]\n    E --> R2[\"Top 7 SQL Samples\"]\n    C[\"Custom Uber Date & Business Rules\"] --> LLM[\"Single LLM Call\"]\n    R1 --> LLM\n    R2 --> LLM\n    LLM --> OUT[\"SQL Query + Explanation\"]\n```\n\nAs Uber onboarded more datasets into production, three systemic bottlenecks broke this architecture:\n\n- \n**DDL Embedding Mismatch:** Vector similarity between a plain-English business question (*\"trips completed yesterday in Seattle\"* ) and raw`CREATE TABLE` DDL statements degraded rapidly as hundreds of tables were added.\n- \n**Context Window Exhaustion:** Wide Tier-1 tables at Uber often exceed**200+ columns** , consuming**40K–60K tokens per table** . Retrieving just three tables blew past early 32K token limits—and continued causing intermittent overflows even after upgrading to**GPT-4 Turbo (1106) with a 128K token window** .\n- \n**Silent Semantic Hallucinations:** Queries frequently compiled and executed without syntax errors while returning zero rows because the LLM guessed wrong enum values (e.g., filtering`status = 'Finished'` when the table stores`'Completed'` ).\n\n## \n  \n  \n  2. Production Architecture: A Progressive Filtering Funnel\n\nInstead of dumping raw schemas into a single prompt, Uber redesigned QueryGPT as a **multi-stage agentic pipeline** that progressively narrows the search radius before generating SQL.\n\n```\nflowchart TD\n    U[\"User Prompt: Tesla trips completed in Seattle yesterday\"] --> IA[\"1. Intent Agent\"]\n    IA --> WS[\"Domain Workspace Routing: Mobility selected out of 12 System Workspaces\"]\n    WS --> RAG[\"Scoped Vector Search: Mobility Tables & SQL Samples\"]\n    RAG --> TA[\"2. Table Agent\"]\n    TA --> HITL{\"Human-in-the-Loop Checkpoint\"}\n    HITL -- \"User edits table list\" --> TA\n    HITL -- \"User clicks Looks Good\" --> CPA[\"3. Column Prune Agent\"]\n    CPA --> SLIM[\"Pruned Schemas: Irrelevant Columns Stripped\"]\n    SLIM --> GEN[\"4. SQL Generation LLM + Custom Date Rules\"]\n    GEN --> FINAL[\"Verified SQL Query + Plain-English Explanation\"]\n```\n\n### \n  \n  \n  Stage 1: Domain Workspaces + Intent Agent\n\nUber partitioned its data catalog into **12 curated System Workspaces**—** Mobility** plus 11 other core domains including **Ads** (Uber Advertising), **Core Services**, **Platform Engineering**, and **IT** (Information Technology)—alongside user-defined **Custom Workspaces** for specialized teams.\n\nEvery request first hits an **Intent Agent** (an LLM classifier) that maps the prompt to one or more workspaces. By locking onto the *Mobility* workspace first, QueryGPT avoids searching unrelated *Ads* or *IT* schemas altogether.\n\n### \n  \n  \n  Stage 2: Table Agent with Human-in-the-Loop (HITL)\n\nEarly user feedback revealed that when upstream table retrieval missed the mark, the final SQL was guaranteed to fail. Uber introduced a **Table Agent** paired with an explicit UI checkpoint:\n\n- The agent proposes candidate tables (e.g., `uber.trips_data` and`uber.dim_city` ).\n- The user can either click **\"Looks Good\"** to proceed or manually add/remove tables before SQL synthesis begins.\n\n### \n  \n  \n  Stage 3: Column Prune Agent\n\nTo eliminate 128K token overflows and reduce inference latency, Uber added a **Column Prune Agent**. Before generating SQL, an intermediate LLM call inspects the user's question and strips out irrelevant columns from each selected table's DDL—shrinking a 200-column schema down to only the handful of fields needed for joins, filters, and projections.\n\n## \n  \n  \n  3. Complete End-to-End Walkthrough\n\nHere is how a real request flows through every stage of the pipeline *(note: `uber.trips_data` is an illustrative table name used in Uber's blog)*:\n\n1. \n**User Prompt:** >*\"Write a query to find the number of trips that were completed by Teslas in Seattle yesterday\"*\n2. \n**Intent Agent Output:** Maps prompt to the**`Mobility`** system workspace.\n3. \n**Table Agent + User Confirmation:** Suggests`uber.trips_data` and`uber.dim_city` → User clicks**\"Looks Good\"** .\n4. \n**Column Prune Agent Output:** Reduces`uber.trips_data` from 200+ columns down to`trip_id` ,`city_id` ,`vehicle_make` ,`trip_status` , and`datestr` (partition key).\n5. \n**Final Generated SQL (incorporating Uber's custom date instructions):**\n\n*(Accompanied by a plain-English explanation of the join, filter conditions, and date partition logic.)*\n\n## \n  \n  \n  4. How Uber Evaluates QueryGPT (Vanilla vs. Decoupled)\n\nBecause LLM outputs are non-deterministic (~5% run-to-run variance), Uber built a golden question-to-SQL benchmark and tracks regressions across two test modes:\n\n- \n**Vanilla Flow:** End-to-end execution where QueryGPT infers intent, tables, and SQL autonomously.\n- \n**Decoupled Flow:** Injects ground-truth intent and tables directly into the generator so engineers can isolate SQL synthesis quality from upstream retrieval errors.\n\n``` php\nflowchart LR\n    G[\"Golden Benchmark Question\"] --> M1[\"1. Intent Accuracy\"]\n    G --> M2[\"2. Table Overlap Score: 0.0 to 1.0\"]\n    G --> M3[\"3. Successful Run: Compiles & Executes\"]\n    G --> M4[\"4. Run Has Output: Rows Greater Than 0\"]\n    G --> M5[\"5. Qualitative Query Similarity: LLM Judge 0.0 to 1.0\"]\n```\n\nEach benchmark run captures **5 distinct signals**:\n\n1. \n**Intent Accuracy:** Did the Intent Agent select the right workspace?\n2. \n**Table Overlap (0 to 1):** Measures retrieval precision. For example, if*\"How many trips were canceled by drivers last week in Los Angeles?\"* requires`[fact_trip_state, dim_city]` and QueryGPT selects`[dim_city, fact_eats_trip]` , the overlap score is**0.5** (1 of 2 required tables matched).\n3. \n**Successful Run:** Does the SQL execute on the engine without syntax or missing-partition errors?\n4. \n**Run Has Output (`rows > 0`):** Catches silent semantic bugs—such as` WHERE status = 'Finished'` instead of`'Completed'` —where a query runs cleanly but returns zero records.\n5. \n**Qualitative Query Similarity (0 to 1):** An LLM judge compares the generated SQL against the golden SQL to verify whether joins, columns, and aggregations are structurally sound even when a minor rule (like a missing partition filter) causes execution to fail.\n\n## \n  \n  \n  Key Architectural Takeaways\n\n1. \n**Bound your retrieval space first:** Domain workspaces + an Intent Agent outperform flat vector search across monolithic enterprise catalogs.\n2. \n**Put humans at high-leverage checkpoints:** Confirming 2–3 table names takes a user two seconds and prevents cascading hallucination in the final SQL.\n3. \n**Prune schemas aggressively:** Treating DDL pruning as its own lightweight agentic step cuts token cost, prevents context overflows, and improves SQL attention accuracy.\n4. \n**Measure silent failures, not just syntax:** A Text-to-SQL query that compiles with zero rows returned is a failure—track non-empty execution alongside structural similarity.", "url": "https://wpnews.pro/news/how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi", "canonical_source": "https://dev.to/chethanramaswamy/how-uber-scaled-text-to-sql-to-12m-monthly-queries-inside-querygpts-multi-agent-architecture-592j", "published_at": "2026-11-25 17:07:05+00:00", "updated_at": "2026-11-25 17:13:05.766449+00:00", "lang": "en", "topics": ["large-language-models", "ai-agents", "ai-tools", "mlops"], "entities": ["Uber", "QueryGPT", "GPT-4 Turbo"], "also_reported_by": [], "takeaway": "Routing prompts through domain workspaces, a table-selection checkpoint, and column pruning before SQL generation keeps wide 200+ column schemas from blowing past even a 128K-token window and reduces silent enum-value hallucinations.", "recommendation": {"advice": "Scope retrieval to curated domain workspaces and prune columns before generating SQL; Uber found naive top-3 table RAG overflowed 128K tokens and returned zero-row queries from wrong enum guesses.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi", "markdown": "https://wpnews.pro/news/how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi.md", "text": "https://wpnews.pro/news/how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi.txt", "jsonld": "https://wpnews.pro/news/how-uber-scaled-text-to-sql-to-1-2m-monthly-queries-inside-querygpt-s-multi.jsonld"}}