# SQLoom: Set-Contrastive Learning of Syntactic, Semantic, and Logical Dependencies for Text-to-SQL

DevFeed: [SQLoom: Set-Contrastive Learning of Syntactic, Semantic, and Logical Dependencies for Text-to-SQL](<https://devfeed.tech/articles/sqloom-set-contrastive-learning-of-syntactic-semantic-and-logical-dependencies-for-text-to-sql-113658.md>)

Original publisher: [Read original article](<https://arxiv.org/abs/2611.03298>)

Author: Hao Fu, Degang Sun, Wan Wei, Jinxia Wei, Chun Long, Peng Gao

Published: 2026-11-03T05:00:00Z

Content type: article

Language: en

Sources: [arXiv: Artificial Intelligence](<https://devfeed.tech/sources/arxiv-artificial-intelligence.md>), [arXiv: Databases](<https://devfeed.tech/sources/arxiv-databases.md>)

Topics: [text2sql](<https://devfeed.tech/topics/text2sql.md>), [AI for SQL query generation](<https://devfeed.tech/topics/ai-for-sql-query-generation.md>), [Large Language Model](<https://devfeed.tech/topics/llm.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>)

Tags: [cs-ai](<https://devfeed.tech/tags/cs-ai.md>), [cs-db](<https://devfeed.tech/tags/cs-db.md>), [database](<https://devfeed.tech/tags/database.md>), [database-schema](<https://devfeed.tech/tags/database-schema.md>), [dataset](<https://devfeed.tech/tags/dataset.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [execution](<https://devfeed.tech/tags/execution.md>), [experiments](<https://devfeed.tech/tags/experiments.md>), [fine-tuning](<https://devfeed.tech/tags/fine-tuning.md>), [gpt-4](<https://devfeed.tech/tags/gpt-4.md>), [large-language-models-llms](<https://devfeed.tech/tags/large-language-models-llms.md>), [llm-agents](<https://devfeed.tech/tags/llm-agents.md>), [logical](<https://devfeed.tech/tags/logical.md>), [natural-language](<https://devfeed.tech/tags/natural-language.md>), [qwen3](<https://devfeed.tech/tags/qwen3.md>), [reinforcement-learning](<https://devfeed.tech/tags/reinforcement-learning.md>), [semantic](<https://devfeed.tech/tags/semantic.md>), [sql](<https://devfeed.tech/tags/sql.md>), [supervised-fine-tuning](<https://devfeed.tech/tags/supervised-fine-tuning.md>), [supervision](<https://devfeed.tech/tags/supervision.md>), [training-dataset](<https://devfeed.tech/tags/training-dataset.md>)

## AI overview

SQLoom fine-tunes open-weight language models for text-to-SQL by contrasting sets of correct queries with minimally different incorrect ones. Its supervision targets SQL syntax and schema validity, alignment with the question, and consistency among dependent clauses. LLM agents propose examples, which a SQL parser and execution on counterexample databases verify. The authors also introduce Spider-Refined, with 378 corrected Spider annotations and enriched schemas. On reported benchmarks, Qwen3-1.7B reaches 88.7% execution accuracy on Spider development, 89.2% on Spider test, and 73.4% on BIRD development; the paper reports stronger results than fine-tuning, reinforcement-learning, and agent baselines up to 70B parameters. On perturbed questions, accuracy drops at most 0.6 points, compared with up to 12.1 for agent methods. Single-pass generation averages 0.42 seconds per query, reported as 23 times faster than a GPT-4-based agent method.

## Source excerpt

arXiv:2611.03298v1 Announce Type: new Abstract: Text-to-SQL translates natural language questions into SQL queries, enabling database access without writing SQL. Fine-tuning open-weight large language models (LLMs) is cost-effective, but existing methods treat SQL as ordinary text and optimize token-level likelihood without explicitly modeling its syntactic, semantic, and logical requirements. Thus, a single incorrect alias or comparison operator can invalidate a query while contributing little to training loss. We propose SQLoom, a constraint-aware fine-tuning framework with supervision at three levels: syntactic validity under SQL grammar and database schema, semantic alignment between query decisions and the question, and logical consistency across dependent clause decisions. SQLoom extends supervised fine-tuning with a unified set-contrastive objective favoring sets of correct outputs over minimally different incorrect ones at each level. LLM agents propose this supervision, which a SQL parser and execution on counterexample databases verify. We also release Spider-Refined, a training dataset correcting 378 flawed Spider annotations and enriching database schemas. Experiments on Spider, BIRD, and three perturbed Spider variants show that SQLoom improves execution accuracy for Qwen3-1.7B from 62.9% zero-shot to 88.7% on Spider development, reaching 89.2% on Spider test and 73.4% on BIRD development. It outperforms fine-tuning, reinforcement learning, and agent-based baselines with up to 70 billion parameters. On question perturbations, SQLoom loses at most 0.6 accuracy points versus up to 12.1 for agent-based methods. It generates SQL in a single pass at 0.42s per query, 23$\times$ faster than a GPT-4-based agent method. These results demonstrate the effectiveness of set-contrastive supervision over token-level training.