Skip to content

    AI Architect Case Files

    Uber QueryGPT Explained: Text-to-SQL Case Study

    How Uber's QueryGPT turns questions into SQL with intent, workspaces, table and column agents, and how it is evaluated. A sourced case from Uber's own post.

    By Published 8 min read

    • ai-architect
    • case-file
    • industry-manufacturing-logistics
    • pattern-text-to-sql-agent
    • failure-wrong-answer
    • kind-public
    Share

    Public case (sourced). Based on Uber Engineering's published post "QueryGPT - Natural Language to SQL Using Generative AI" (2024-09-19); every fact below is attributed to it.

    This case belongs to Agents, Tools and MCP. The post is the only source; where it says nothing, this page says so, and the diagrams draw only the elements the post names.

    Context

    • Uber's post says that SQL is used daily by engineers, operations managers and data scientists, and that writing queries takes SQL syntax and knowledge of Uber's internal data models.
    • It says the data platform handles approximately 1.2 million interactive queries each month, and that the Operations organisation, one of the largest user cohorts, contributes about 36% of them.
    • The post says QueryGPT began at Uber's Generative AI Hackdays in May 2023. It describes two of about 20+ iterations: a first version and the current design.

    Problem statement

    What the post says Value
    Authoring: search the data dictionary for relevant datasets, then write the query Around 10 minutes per query
    QueryGPT (the post's own claim) Can generate reliable queries in about 3 minutes

    The post does not say how either figure was measured, and it states no other numeric target.

    Constraints

    Everything below is stated in the post.

    • Schema size. Some tier 1 tables have schemas spanning over 200 columns, which could use 40-60K tokens in the request. The post says that 3 or more of these tables would break the LLM call, since the largest available model at the time supported only 32K tokens.
    • Non-determinism. Identical runs can differ; Uber does not over-index decisions on about 5% run-to-run changes in most metrics.

    Why the traditional approach fell short

    Two approaches fell short according to the post: manual authoring (see the problem statement) and the team's own first version, a simple retrieval-augmented design (Option B below). The post names three problems with the first version:

    1. Similarity search of a raw prompt against schema samples and SQL queries did not return relevant results.
    2. Going from a natural language prompt to the right schemas was very difficult.
    3. Having 3 or more of the large schemas would break the LLM call.

    The post does not discuss other tools such as BI products or semantic layers.

    Options considered

    Option What the post says Outcome
    A. Write the SQL by hand (non-AI, the status quo) Around 10 minutes per query; needs SQL and data-model knowledge The problem QueryGPT addresses
    B. First version: simple retrieval with few-shot prompting Vectorised the user's prompt and ran a k-nearest-neighbour search over SQL samples and schemas to fetch 3 relevant tables and 7 relevant SQL samples; sample data set of 7 tier 1 tables and 20 SQL queries Accuracy declined as more tables and samples were onboarded; replaced
    C. Current design: workspaces and a chain of narrow LLM agents Intent agent, Table agent, Column Prune agent, described below The design the post describes as current

    The post does not describe other options it considered.

    Solution architecture

    Figure 1. The current design as the post describes it

    QueryGPT current design as described by UberUser prompt to Intent agent; Intent agent to Workspaces (maps to); Workspaces to Table agent; Table agent to Column prune agent; Column prune agent to Query generation; Query generation to SQL and explanationUser promptUser promptIntent agent: LLM callIntent agentLLM callWorkspaces: system or customWorkspacessystem or customTable agent: user can editTable agentuser can editColumn prune agent: LLM callColumn pruneagentLLM callQuery generationQuerygenerationSQL and explanation: outputSQL andexplanationoutputmaps to

    How to read this: every prompt runs through the intent agent first; the post does not state the order of the table and column prune agents.

    Figure 2. One question through the agents

    sequenceDiagram accTitle: QueryGPT request path from the published post accDescr: The user's prompt goes to the intent agent, which selects workspaces. The table agent proposes tables and the user confirms or edits them. The column prune agent trims the schemas, the query is generated, and the user gets SQL with an explanation. The figure follows the order in which the post presents the agents, which it does not state explicitly. The post says invented tables or columns remain an unsolved problem. participant U as User participant I as Intent agent participant T as Table agent participant C as Column prune agent participant G as Query generation U->>I: natural language prompt I-->>T: workspaces selected T-->>U: proposed tables U->>T: Looks Good, or an edited list Note over T,C: The post does not state the order of these two agents T->>C: tables and their schemas C->>G: pruned schemas G-->>U: SQL query and explanation Note over G,U: The post says hallucinated tables or columns are not solved

    How to read this: the user confirms the table list, and the last note marks the failure the post says it has not solved.

    How AI solved it, step by step

    Per the post, one request goes like this. Step through it.

    One QueryGPT request, per Uber's post (interactive when JavaScript is on)
    1. The user writes a prompt. For example: "Write a query to find the number of trips that were completed by Teslas in Seattle yesterday".
    2. Intent agent. An LLM call maps the question to one or more business domains or workspaces, and through them to SQL samples and tables. Picking a business domain drastically narrowed the search radius for retrieval.
    3. Workspaces. A curated collection of SQL samples and tables for a domain (the post lists Mobility, Ads and Core Services). Uber shipped 11 other system workspaces besides Mobility; users can create custom ones.
    4. Table agent, then the user. Another LLM agent picks tables, added after some users reported that the tables QueryGPT picked were not correct. Users can confirm the list (Looks Good) or edit it.
    5. Column prune agent. An LLM call prunes irrelevant columns from the schemas. The post does not state the order of the table and column prune agents.
    6. Query generation and output. The output keeps the structure of the first version: a SQL query and an explanation of how it was generated. The post gives no detail on this step.

    The post does not say which model runs each agent or how long the chain takes.

    Under the hood

    The mechanism the post spells out is the token budget (the schema limits are under Constraints).

    What the post says Detail
    Model used GPT-4 Turbo with a 128K limit (1106), and still intermittent token limit issues for some requests
    Fix The column prune agent: it improved the token size and, by extension, the cost of each call, and reduced latency because inputs were smaller. No figures given

    An arithmetic check, which is this page's and not a figure from the post: three tables at the post's 40-60K range would use 3 x 40K = 120K to 3 x 60K = 180K tokens of schema, which can exceed a 128K limit before samples, instructions and the answer are counted.

    The post prunes schemas once, before generation, and does not call this compaction. See context growth and compaction in the lesson.

    What went wrong / failure modes

    The post reports these problems.

    Problem What the post says
    Accuracy fell as tables were added; some users reported wrong tables; token-size failures Addressed by workspaces and the intent agent; the table agent with a confirm-or-edit step; the column prune agent
    Hallucinated tables and columns The LLM sometimes generates queries with tables that do not exist; not completely solved. The post mentions prompt changes and a chat mode, and says Uber is looking to add a "Validation" agent that recursively tries to fix them
    Queries that run but return nothing A hallucinated filter such as status = "Finished" instead of "Completed"; this is why its metrics count whether a run has output
    Similarity is not correctness A question regularly fails because it omits a partition filter, although the LLM similarity score rates it as similar to the golden SQL

    How the post evaluates

    It builds a golden set from real questions in QueryGPT logs, with intent, schemas and SQL verified manually. Per question it records:

    Metric What it is
    Intent accuracy Was the intent right
    Table overlap 0 to 1; in the post's example two tables were required, one was identified, and the score is 0.5
    Successful run Did the query run
    Run has output Did it return more than 0 records
    Similarity An LLM scores the query against the golden SQL between 0 and 1

    Figure 3. The two evaluation flows

    flowchart TB accTitle: QueryGPT evaluation flows from the post accDescr: In the vanilla flow a question goes through intent and dataset inference, SQL generation from the inferred values, and evaluation. In the decoupled flow the intent and datasets are supplied with the question, SQL is generated from those actual values, and the result is evaluated, so mistakes in intent or table selection do not carry into the SQL step. subgraph VF["Vanilla flow: baseline"] V1["Question"] --> V2["Infer intent and datasets"] --> V3["Generate SQL from inferred values"] --> V4["Evaluate intent, datasets and SQL"] end subgraph DF["Decoupled flow: component level"] D1["Question, intent and datasets supplied"] --> D2["Generate SQL from the supplied values"] --> D3["Evaluate intent, datasets and SQL"] end

    How to read this: per the post, the vanilla flow measures baseline performance and the decoupled flow enables component-level evaluation by removing dependencies on earlier outcomes.

    The post describes the decoupled flow as measuring performance with the human-in-the-loop experience.

    Results

    Only the post's own numbers are used here.

    What the post reports Value
    Limited release Some Operations and Support teams
    Daily active users About 300 on average
    Users saying the generated queries reduced the time they would otherwise spend writing queries from scratch About 78%
    Estimated time to author a query About 10 minutes by hand against about 3 minutes with QueryGPT

    The post publishes no accuracy figures, latency, cost or golden-set size; the 78% is user-reported, not a measured accuracy.

    Tradeoffs and when NOT to use this approach

    This section is this page's reading of the post, not statements by Uber.

    • Each agent is another LLM call; the post gives no end-to-end latency or cost figures.
    • The first version worked well for a small set of schemas, so simple retrieval can be enough when there are few.
    • Silent errors, such as a query on the wrong table, matter most for users who cannot read SQL; the post advises targeting the right personas first.
    • The post does not say how access control or data privacy are handled, so a team with strict data permissions needs its own answer.

    Design rules extracted

    1. Narrow the search space before retrieving. The post's workspaces and intent agent cut the retrieval radius.
    2. Give each LLM step one narrow job. The post says the LLMs worked well when given a small unit of specialised work.
    3. Add a human confirmation where users report errors, such as the table list.
    4. Cut the context before the expensive call; the post's column prune agent did this for schemas.
    5. Evaluate components separately on a golden set from real logs, and check that queries run and return rows.

    Sources

    • Jeffrey Johnson, Callie Busch and Abhi Khune, "QueryGPT - Natural Language to SQL Using Generative AI", Uber Engineering, 2024-09-19: https://www.uber.com/blog/query-gpt/ (accessed 2026-10-21, re-checked 2026-10-22). All facts above are from this post.

    Last verified: 2026-10-22

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments