Text-to-SQL is the task of turning a question written in plain language, such as "which customers ordered more than twice last month?", into a SQL query that a database can run. Natural language querying (NLQ) is the same idea applied to any query language, including the ones monitoring products use for metrics, logs and cloud resources. The appeal is access. Most of the data in a company sits behind a query language that only some people know, and a working translator lets anyone ask.
The hard part is rarely the SQL grammar. It is matching the words in a question to the right tables, columns and values in a particular database, a step called schema linking, and doing it when real schemas have hundreds or thousands of columns and real questions are vague. A query can also be almost right, with the correct table but a missing filter, and still return a wrong answer that looks plausible. Research on the task has followed general language models from small trained parsers to prompted and fine-tuned LLMs, while benchmarks have moved from tidy academic databases toward enterprise ones where the best systems still fail most tasks.
How it works
A typical pipeline has four stages. Schema linking picks the tables and columns the question needs. Generation writes one or more candidate queries. Revision runs the candidates, looks at errors or results, and asks the model to fix them. Selection picks a final query, sometimes by merging candidates whose results disagree.[8] Text-to-SQL is one case of semantic parsing, the general problem of mapping language to a formal representation that a program can execute (see Task-oriented dialogue and semantic parsing).
Schema linking
A 2020 study argued that schema linking had been treated as a minor preprocessing step, often simple string matching between the question and column names, when it was the crux of the task. With good schema linking, a simple BERT-based model did well on Spider, a widely used benchmark of questions over many databases, and many remaining errors came from noise in the dataset.[2] Later work kept refining the step. One method first writes a draft query against the full schema, then keeps only the tables and columns that draft used and writes the final query against that smaller schema.[3] Another links at three levels (column, table and whole database) and repeats the step to keep trimming redundant schema.[7] PAS-SQL splits the problem into two gaps. The structural gap is the distance between how a question is phrased and how the SQL is shaped. The lexical gap is the distance between the question's words and the schema's names. It closes the first by retrieving examples with a similar question structure and the second by marking which words in the question refer to which tables or columns.[9]
Larger context windows put the whole step in question. A 2024 paper found that newer models use the relevant schema well even when many irrelevant columns are present, so its pipeline skips schema linking whenever the schema fits in the model's context window. Filtering can drop a column the query needs, and that error cannot be recovered later. The pipeline ranked first on BIRD, a text-to-SQL benchmark built on large, messy real databases, at 71.83 percent accuracy.[4]
Prompting or fine-tuning
Methods split into in-context learning, which prompts a strong closed model with examples, and supervised fine-tuning of an open model. Prompting a frontier model is the simpler route to high accuracy. The BASE-SQL authors argue that data privacy, generation speed and cost favor fine-tuning in practice. Their pipeline fine-tunes Qwen2.5-Coder-32B-Instruct, an open coding model from Alibaba, and reports 67.47 percent on the BIRD development set and 88.9 percent on the Spider test set, ahead of several systems built on GPT-4o, with about five model calls per query.[8]
Knowing when not to answer
Ambiguous questions produce confident wrong queries. Reliable Text-to-SQL adds abstention. It estimates, from the model's internal states, whether its schema linking is likely wrong, and when it is unsure it stops or asks the user to choose an interpretation. With a person resolving the uncertain cases, schema linking on BIRD was near perfect, and a small query-generation model came close to the accuracy of far larger ones.[6]
Benchmarks and their limits
Spider is the benchmark on which most of this work reports results. A 2024 study found its questions overly specific and unnatural, with little variation in phrasing, so models that parsed a question correctly often failed on a small rewording. Using an LLM to write more varied paraphrases doubled the number of Spider questions, and training on the larger set improved results on tests of rewording and on out-of-domain data.[1]
Spider 2.0, from late 2024, tests 632 tasks drawn from enterprise use, on databases that often have more than 1,000 columns and live in cloud systems such as BigQuery and Snowflake. Solving them often means reading metadata, dialect documentation or a project's code, and writing queries over 100 lines long. An agent built on o1-preview, an OpenAI reasoning model, solved 17.0 percent of the tasks, against 91.2 percent on the original Spider and 73.0 percent on BIRD.[5] The gap is a measure of how far the academic setting is from production data.
Production teams meet a second problem, grading. Datadog's Cloud Cost Management team built an NLQ agent that turns questions such as "Show AWS database costs by service for September" into a metrics query. Comparing the generated query with an expected one as text gave success rates as low as 2 percent, though the agent was doing far better. They split correctness into separate checks for syntax, metric choice, time aggregation, grouping and filters. The checks showed that most errors came from filters, in particular matching tag values.[11] The same split, scoring each part of the output instead of the whole string, applies to evals for any structured output.
In products
Monitoring tools have adopted NLQ. Datadog's posts give two reasons: writing a query takes deep familiarity with metric names, tags and syntax, and during an incident people need answers fast.[13][10] Datadog, an observability company, announced Bits AI in August 2023 with natural language queries over metrics, traces, logs and other data, translated into the right syntax using how a customer has tagged their services.[10] Later features applied the same idea product by product. Resource Catalog translates a question such as "RDS instances in production without storage encryption enabled, grouped by team" into a structured filter on cloud resources.[12] Natural Language Queries for metrics picks the metric, filters, aggregation and grouping, and accepts follow-ups such as "Only show production".[13] DDSQL Editor builds SQL over telemetry from a typed question,[15] and in June 2026 the company's Bits Chat assistant added query writing, explanation and optimization there.[14]
These products share a design choice. The generated query is shown to the user, who can edit, accept or discard it,[13][15] so the person can check the translation before trusting the answer.
History and timeline
- Nov 2020: a study argues that schema linking is the crux of text-to-SQL.[2]
- Aug 2023: Datadog announces natural language queries in Bits AI.[10]
- Feb 2024: LLM-written paraphrases make Spider-trained parsers handle rewording better.[1]
- May 2024: SQL-to-Schema derives the schema from a draft query.[3]
- Aug 2024: "The Death of Schema Linking?" drops the step when the schema fits in context.[4]
- Nov 2024: Spider 2.0 appears; its authors' agent solves 17 percent of the enterprise tasks.[5]
- Jan to Feb 2025: abstention for uncertain schema linking, progressive schema linking, the BASE-SQL baseline for open models, and PAS-SQL.[6][7][8][9]
- Jan 2026: Datadog engineers describe component-level evaluation of an NLQ agent.[11]
- Mar to Jun 2026: Datadog writes up NLQ in Resource Catalog and metrics, and adds Bits Chat query writing to DDSQL Editor.[12][13][14]
My position
In 2024 I wrote, about task-oriented dialogue, that having the model emit an intermediate program gives control and auditability, because the plan can be checked or shown to the user before anything runs.[16] The argument carries over to a generated query, and it is how the natural language queries I built at Datadog work (my own account, Dec 2026): the user gets a query they can read and edit, not an answer (Natural language querying at Datadog).[13]
The order of work I follow comes from fine-tuning small models for special purposes over three years. First build an eval dataset and get a prompt working on a general model, even a slow and expensive one. Fine-tune afterwards, and only for cost and latency.[17] A small model loses world knowledge and fails badly on questions outside its training distribution, so the eval set has to be broad.[17] For text-to-SQL that means real questions with all their vagueness, which is the gap the Spider paraphrase study and Spider 2.0 both point at.[1][5]
Criticism and counterpoints
Schema linking is a test case for the The bitter lesson, the argument that general methods riding on more compute beat hand-built ones. Linking modules were worth building when models could not hold a whole schema, and the 2024 finding that skipping the step wins once the schema fits in context points the same way.[4]
Spider 2.0's 17 percent cuts against treating text-to-SQL as solved, and against shipping it to people who cannot read the query it returns.[5] Showing the query helps experts, but a person who could not write the query may not catch a wrong filter in it, and filters were the main source of error in Datadog's own evaluation.[11]
Dropping schema linking has limits. It applies only when the whole schema fits in context, and Spider 2.0 databases with more than 1,000 columns, plus documentation and code, often will not.[4][5] Fine-tuning has defenders on grounds I share, including privacy and speed,[8] but each new base model resets the work of tuning data and settings.[17] Abstention trades automation for accuracy, since it relies on a person to answer the clarifying question.[6]
Open questions
- Does schema linking survive as a retrieval problem for schemas too large for any context window, or do longer contexts end it?
- How should a tool show a generated query to someone who cannot read the query language?
- Can component-level scores, like the ones Datadog's team used, become a standard benchmark metric in place of exact match or execution accuracy?
- When will a general model with a good prompt be fast and cheap enough that fine-tuned query models are no longer worth their upkeep?
See also
Change log
- 2026-12-03: First written, from papers on schema linking, benchmarks, fine-tuning and abstention, public Datadog documentation and blog posts on natural language querying, and my posts on task-oriented dialogue and fine-tuning.
Reading
References
- ^ Saparina and Lapata, Improving Generalization in Semantic Parsing by Increasing Natural Language Variation
- ^ Lei et al., Re-examining the Role of Schema Linking in Text-to-SQL
- ^ Yang et al., SQL-to-Schema Enhances Schema Linking in Text-to-SQL
- ^ Maamari et al., The Death of Schema Linking? Text-to-SQL in the Age of Well-Reasoned Language Models
- ^ Lei et al., Spider 2.0: Evaluating Language Models on Real-World Enterprise Text-to-SQL Workflows
- ^ Chen et al., Reliable Text-to-SQL with Adaptive Abstention
- ^ Yang et al., PSM-SQL: Progressive Schema Learning with Multi-granularity Semantics for Text-to-SQL
- ^ Sheng et al., BASE-SQL: A powerful open source Text-To-SQL baseline approach
- ^ Kong et al., Bridging the Gap: Transforming Natural Language Questions into SQL Queries via Abstract Query Pattern and Contextual Schema Markup
- ^ Introducing Bits AI, your new DevOps copilot (Datadog blog, Aug 2023)
- ^ How we cut our NLQ agent debugging time from hours to minutes with Agent Observability (Datadog blog, Jan 2026)
- ^ Use plain English to query your multi-cloud infrastructure in Resource Catalog (Datadog blog, Mar 2026)
- ^ Explore Datadog metrics with Natural Language Queries (Datadog blog, May 2026)
- ^ DASH 2026 Harnessing AI: Guide to Datadog's newest announcements (Datadog blog, Jun 2026)
- ^ DDSQL Editor (Datadog documentation)
- ^ Task Oriented Dialog Systems (post, Oct 2024)
- ^ Fine-tuning small models is a fast way to learn the bitter lesson (post, Oct 2026)