formal-query-synthesis CAP-0052 · activeWriting a reusable locator: regex, SQL, XPath
Whether a model can turn an intent or a few examples into a grep pattern, regex, SQL query, XPath or jq path that selects the right subset, so the pattern runs over the whole collection without calling the model again.
Also called: locator generation, pattern synthesis, text-to-SQL, regex generation, programming by example, grep, grep-style locators
Tags: coding-agent, general
Proposed 2026-09-19 from ten papers forwarded by Russ under the heading "grep-style locators": neural regex generation (Locascio 2016, SemRegex 2018, REGEL 2019, Zelina 2024), example-driven extractors (FlashExtract 2014, wrapper induction 2000), text-to-SQL (Spider 2018, the 2024 survey) and XPath agents (2025). The pipeline's proposal stage judged three of the ten as pointing at a capability the map lacked and consolidated them into this one; the other seven it read as covered by code-generation, but they are filed here as sources because the set was forwarded as one idea. What makes it distinct from ordinary code generation is the success test: the artefact is judged by whether it selects the right subset (DFA equivalence, execution accuracy, transfer to unseen pages), not by whether it reads correctly, and many different strings mean the same thing. The practical stake is cost: a locator that works is paid for once; a model that must be called per document is paid for every time.
What counts as this capability
Scope boundary used when deciding whether a paper is really about this capability, rather than merely mentioning it.
In scope when the output is a pattern-language artefact (regex, SQL, XPath, CSS selector, jq, a grammar) and the paper measures whether it selects or matches correctly against intent or examples. NOT in scope for general code generation from a specification, nor for the model itself extracting the records at inference time without emitting a reusable pattern.
Claims
- mechanismmechanism reasoning↑1↓0For collections of template-generated pages, a delimiter-based extraction pattern induced from a handful of labelled examples can be reused across the rest of the collection, so extraction cost per page drops to pattern execution rather than per-page inference.
- observationsingle paper↑1↓0For extracting fields from vertical websites, decomposing XPath induction into separate sub-tasks over a few seed pages lets an LLM emit an XPath that generalizes to unseen pages of the same site, beating single-prompt CoT and Reflexion XPath generation by 14.84-23.86 F1 points, while calling the model only a handful of times instead of once per page.
- observationsingle paper↑1↓0For grammar-constrained text-to-SQL decoding with small models (Qwen2.5-Instruct 0.5B-7B on Spider), beam search is at least as accurate as sample-and-vote at every matched compute budget of 1-8, and better in most, reversing the usual unconstrained finding that sampling with voting beats beam search.
- observationsingle paper↑1↓0For inducing regular expressions from a handful of labelled examples (entity spans in Czech clinical notes), prompting an LLM and then iteratively refining the pattern against match failures extracts entities more accurately than genetic-programming regex induction, with the margin largest when few examples are available.
- observationsingle paper↑1↓0For instruction tuning an 8B open model on text-to-SQL, a curated set of under 900 examples selected to cover every table in the target schemas and score well on question-SQL alignment reaches higher execution accuracy than pipelines trained on tens of thousands to millions of samples, and dropping the schema-coverage term from the selection objective costs more accuracy than dropping any single quality term.
- observationsingle paper↑1↓0In multi-turn text-to-SQL where an underspecified question hides two dependent clarification layers, current LLM agents almost never surface both layers (joint identification under 5% for all 12 models tested), and this is not explained by how often they ask: ask rates spanning under 10% to over 60% all produce joint identification below 4%, and second-layer identification stays low (1.2-13.8%) even when the first layer is pre-resolved for them.
- observationsingle paper↑1↓0On natural-language-to-SQL synthesis over multi-table databases, a model's accuracy overstates its ability whenever the same database or the same query appears in both training and test: splitting by database rather than by example cut the best system's exact-match accuracy from 33.0% to 12.4%, and accuracy falls further as the target database has more foreign keys.
- observationsingle paper↑1↓0When post-training a 7-8B open model for text-to-SQL with a fixed budget of synthetic examples drawn from a large external pool, selecting examples whose schema-independent SQL skeletons are farthest from those already in the seed set (greedy K-center) rather than sampling randomly from the same pool yields a small in-domain gain and a larger cross-domain one (BIRD dev 64.9 vs 64.4, Spider Test 85.3 vs 83.4, Science Benchmark 53.9 vs 49.8).
- mechanismsingle paper↑1↓0In a prompted text-to-SQL agent, a blanket output-shaping instruction in the system prompt (here "LIMIT 10") is applied by the model to every generated query regardless of the question's intent, truncating answers that legitimately need many rows, so removing it raises execution accuracy most on questions whose correct result set is large.
- mechanismsingle paper↑1↓0For selecting among multiple generated SQL candidates, a listwise selector given retrieved structured selection criteria distilled from training question-SQL pairs, with candidates grouped by execution result and permuted only within groups, reaches higher execution accuracy than pointwise, pairwise and multi-selector baselines on the same candidate pools while using far fewer selector calls and tokens.
- mechanismsingle paper↑1↓0For structured extraction from text files, web pages and spreadsheets, a few user-highlighted example fields are enough to synthesise a reusable extraction program that pulls the remaining fields without further interaction — the locator can be inferred from examples rather than written or re-invoked per record.
- mechanismsingle paper↑1↓0For synthesizing regexes from user intent, neither a natural-language description nor positive/negative examples alone is sufficient — descriptions are ambiguous and small example sets underdetermine the pattern — so a system that parses the description into a structural sketch and uses it to guide example-based search solves far more tasks than either modality alone (80% vs 43% NL-only and 26% examples-only on 300+ regexes).
- mechanismsingle paper↑1↓0For synthesizing reusable XPath extractors from a few sampled web pages, a two-stage pipeline — first having a cheaper model extract both the target value and the neighbouring cue text from an attribute-stripped HTML tree, then having a stronger model write the XPath over HTML condensed around those located nodes with an execution-feedback loop — reaches usable extraction F1 on multi-domain product/listing pages while keeping prompt size far below feeding raw pages.
- observationsingle paper↑1↓0On text-to-SQL benchmarks, aggregate accuracy hides a steep difficulty gradient: pre-trained-language-model-based parsers resolved roughly 80% of Spider cases overall but only about 50% of its extra-hard cases, and as natural-language understanding improved the residual errors shifted toward database-side problems — large schemas, ambiguous columns, dirty cell values — rather than language parsing.
- mechanismsingle paper↑1↓0On text-to-SQL questions that are underspecified with respect to the schema, retrieving clause-level fragments (conditions, joins, calculations, groupings, output specs) from a database's own past successful SQL queries and prepending them to existing few-shot pipelines raises execution accuracy across four different pipelines, but the gain saturates and can reverse once too many candidates are retrieved, because high recall with low precision lets the generator pick a plausible-but-wrong pattern.
- mechanismsingle paper↑1↓0When training a sequence-to-sequence model to generate regular expressions from natural language, rewarding semantic equivalence to the reference (checked by DFA equivalence and test cases) yields more semantically correct regexes than maximum-likelihood training on the reference string, because one intent has many syntactically different equivalent regexes.
- observationsingle paper↑1↓0For translating English descriptions into regular expressions, a generic attention-based sequence-to-sequence model trained only on description/regex pairs matches a domain-engineered semantic parser on a small corpus (814 examples) and beats it by a wide margin once the training corpus is scaled to 10,000 pairs, with no semantic-equivalence machinery built in.
Techniques
- Drop blanket row-limit instructions from text-to-SQL promptspromptingRemove global output-shaping directives such as "LIMIT 10" from the SQL-generation system prompt so row count is decided by the question rather than the prompt.
- Extract cue text first, then write XPath over condensed HTMLpromptingStage one prompts an LLM on a sanitized HTML tree to return target values plus the anchor text preceding them; stage two condenses the page around those nodes and prompts a stronger LLM to emit an XPath, refined by executing it on seed page
- Fill SQL-skeleton coverage gaps, don't just add datatrainingAbstracts SQL queries into schema-independent skeletons, treats seed skeletons as fixed K-center centers, greedily selects external pool skeletons farthest from existing coverage, and re-instantiates each on a target training database with
- Generate regexes from a grammar, then crowd-paraphrasetrainingBuild a large NL-to-regex training corpus by stochastically generating regexes with a small hand-written grammar that also emits rigid synthetic descriptions, then paying crowd workers to paraphrase those descriptions into fluent language.
- Group candidates by execution result, then permute within grpromptingReplaces selector fine-tuning with retrieved structured criteria (schema grounding, SQL operations, expected output form) prepended to a listwise prompt, and mitigates position bias by shuffling only inside execution-result groups, aggregat
- Induce a reusable delimiter wrapper from labelled examplestoolingLearn a delimiter-based extraction pattern from a few labelled example pages, then run that pattern over the whole template-like collection instead of processing each page individually.
- Induce regexes by prompting, then refine against failed matcpromptingPrompt an LLM to write a regex from example spans, run it over the examples, and feed the mismatches back for iterative pattern revision.
- Induce XPath from seed pages via multi-task decompositionpromptingSplit XPath generation into separate sub-tasks the LLM solves over a few seed pages, producing a reusable XPath applied to all remaining pages without further model calls.
- Parse the description into a sketch, then search with exampltoolingConvert the English description into a hierarchical sketch with constrained holes, then run a programming-by-example search that uses the sketch's hints both to prioritize expansion and to over/under-approximate partial programs for pruning
- Prefer beam search over sample-and-vote under grammar constrdecodingWhen output is masked to a formal grammar, spend inference budget on wider beams rather than on sampling several candidates and voting on their execution results.
- Retrieve clause-level knowledge from a database's SQL query retrievalParse past SQL into five categories of clause-level fragments, describe each in natural language, retrieve by query- and component-level embedding similarity, then LLM-rerank before prepending to an existing few-shot text-to-SQL prompt.
- Select a tiny SQL tuning set for schema coverage, not sizetrainingFilter candidate text-to-SQL examples by dual-model difficulty, attach the shortest correct chain-of-thought, score each on four LLM-judged quality dimensions, then use a genetic search to pick a small subset maximizing table/column coverag
- Split text-to-SQL evaluation by database, not by questionprocessEvaluate SQL synthesis on databases and query patterns that never appear in training, so memorized question-query templates cannot be reused.
- Synthesise an extractor from highlighted examplestoolingThe user highlights a few instances of each field and a program-synthesis engine infers an extraction program in a restricted DSL that is then run over the whole document.
- Train on semantic equivalence, not string matchtrainingReplaces the MLE objective with a reward that maximizes expected semantic correctness of the generated regex, measured by a DFA-equivalence oracle plus random and distinguishing test cases.
Sources
Every paper, post or observation behind this capability. Ones cited by a claim show the claim and its stance; ones filed directly are about the capability but have no claim drafted from them yet. Open one to add support or contest it.
- ↑ supports a claim here
- An Iterative LangGraph Agent for Text-to-SQL: Natural Language Access to the Chicago Crime Database2026-09-19↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- BIRD-History: A Benchmark for History-Driven Text-to-SQL with Fine-Grained Knowledge Annotations2026-08-29↑ supports a claim here
- ↑ supports a claim here
- COAL-SQL: Coverage-Guided Augmentation and Failure-Driven Learning for Text-to-SQL Post-Training2026-08-04↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
- Neural Generation of Regular Expressions from Natural Language with Minimal Domain Knowledge2016-08-09↑ supports a claim here
- ↑ supports a claim here
- ↑ supports a claim here
Capabilities are a way of carving up the subject, and carvings are arguable. Say so if this one is wrong — especially a proposed one, which a pipeline added because several papers used the same framing, not because anyone decided it was right.