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arxiv:2603.16448
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# TrustSQL
|
| 13 |
+
|
| 14 |
+
**Tool-Integrated Multi-Turn Reinforcement Learning for Text-to-SQL over Unknown Schemas**
|
| 15 |
+
|
| 16 |
+
[](https://arxiv.org/abs/2603.16448)
|
| 17 |
+
[](https://github.com/JaneEyre0530/TrustSQL)
|
| 18 |
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
| 19 |
+
|
| 20 |
+
TrustSQL (**T**ruthful **R**easoning with **U**nknown **S**chema via **T**ools) is an agentic Text-to-SQL framework for settings where the complete database schema is not pre-loaded into the model context. Instead of passively translating a question from a full schema dump, the agent actively explores the database, verifies relevant metadata, generates candidate SQL, and confirms the final answer.
|
| 21 |
+
|
| 22 |
+
## Highlights
|
| 23 |
+
|
| 24 |
+
- **Unknown Schema reasoning:** retrieve only the metadata needed for the current question.
|
| 25 |
+
- **Four-phase interaction protocol:** `Explore → Propose → Generate → Confirm`, with iterative refinement when more information is needed.
|
| 26 |
+
- **Phase-Aware GRPO:** separate schema-grounding and SQL-generation learning signals with token-level masked advantages.
|
| 27 |
+
- **Execution-coupled schema reward:** give schema credit when the proposed schema is correct and the resulting SQL executes correctly.
|
| 28 |
+
- **Multiple scales:** released checkpoints include 4B and 8B variants; the research results also report a 14B variant.
|
| 29 |
+
|
| 30 |
+
## Collection
|
| 31 |
+
|
| 32 |
+
| Type | Repository | Description |
|
| 33 |
+
|---|---|---|
|
| 34 |
+
| Model | [`AIJian/TrustSQL-4B`](https://huggingface.co/AIJian/TrustSQL-4B) | 4B TrustSQL checkpoint based on Qwen3-4B |
|
| 35 |
+
| Model | [`AIJian/TrustSQL-8B`](https://huggingface.co/AIJian/TrustSQL-8B) | 8B TrustSQL checkpoint based on Qwen3-8B |
|
| 36 |
+
| Dataset | [`AIJian/TrustSQL-data`](https://huggingface.co/datasets/AIJian/TrustSQL-data) | Training data for TrustSQL |
|
| 37 |
+
| Overview | [`AIJian/TrustSQL`](https://huggingface.co/AIJian/TrustSQL) | Project overview, results, usage, citation, and links |
|
| 38 |
+
|
| 39 |
+
## Results
|
| 40 |
+
|
| 41 |
+
All results below use the **Unknown Schema** setting, without pre-loaded database metadata. Execution Accuracy (EX) measures whether the generated SQL returns the same result as the reference query.
|
| 42 |
+
|
| 43 |
+
### BIRD-Dev
|
| 44 |
+
|
| 45 |
+
| Model | Greedy | Majority voting |
|
| 46 |
+
|---|---:|---:|
|
| 47 |
+
| TRUST-SQL-4B | 64.9 | 67.2 |
|
| 48 |
+
| TRUST-SQL-8B | 65.8 | 67.7 |
|
| 49 |
+
| TRUST-SQL-14B | 68.1 | 70.1 |
|
| 50 |
+
|
| 51 |
+
### Robustness and compositional benchmarks
|
| 52 |
+
|
| 53 |
+
| Model | Spider-Test | Spider-DK | Spider-Syn | Spider-Realistic |
|
| 54 |
+
|---|---:|---:|---:|---:|
|
| 55 |
+
| TRUST-SQL-4B | 82.8 / 85.0 | 71.6 / 73.8 | 74.7 / 77.3 | 79.9 / 82.5 |
|
| 56 |
+
| TRUST-SQL-8B | 83.9 / 86.5 | 72.1 / 75.7 | 75.4 / 77.4 | 82.1 / 84.1 |
|
| 57 |
+
| TRUST-SQL-14B | 83.9 / 86.5 | 75.0 / 78.6 | 78.4 / 79.7 | 82.7 / 86.5 |
|
| 58 |
+
|
| 59 |
+
Each entry is `Greedy / Majority voting`.
|
| 60 |
+
|
| 61 |
+
On BIRD-Dev, the framework improves over the corresponding base models by an average of **30.6 absolute points** for the 4B model and **16.6 absolute points** for the 8B model across the five evaluation benchmarks.
|
| 62 |
+
|
| 63 |
+
## How it works
|
| 64 |
+
|
| 65 |
+
### 1. Explore Schema
|
| 66 |
+
|
| 67 |
+
Use metadata tools to discover tables, columns, foreign keys, and relevant value patterns. Schema knowledge must come from verified tool observations rather than model memory.
|
| 68 |
+
|
| 69 |
+
### 2. Propose Schema
|
| 70 |
+
|
| 71 |
+
Commit to the currently verified tables and columns. This explicit checkpoint reduces schema hallucination and defines the boundary for schema-specific credit assignment.
|
| 72 |
+
|
| 73 |
+
### 3. Generate SQL
|
| 74 |
+
|
| 75 |
+
Generate and execute a candidate SQL query using the proposed schema. The execution result provides feedback for query refinement.
|
| 76 |
+
|
| 77 |
+
### 4. Confirm Answer
|
| 78 |
+
|
| 79 |
+
Return the final SQL answer after the schema and query have been validated. The workflow can revisit earlier phases when additional evidence is needed.
|
| 80 |
+
|
| 81 |
+
## Training
|
| 82 |
+
|
| 83 |
+
The TrustSQL training recipe uses a two-stage pipeline:
|
| 84 |
+
|
| 85 |
+
1. **SFT warm-up:** 9.2k structured demonstrations teach the interaction protocol.
|
| 86 |
+
2. **Phase-Aware GRPO:** 11.6k RL samples optimize schema exploration and SQL generation with separate masked advantages.
|
| 87 |
+
|
| 88 |
+
The method is implemented with the SLIME training framework. The experiments use Qwen3-4B, Qwen3-8B, and Qwen3-14B as base models.
|
| 89 |
+
|
| 90 |
+
## Usage
|
| 91 |
+
|
| 92 |
+
The checkpoints are intended for **tool-integrated multi-turn inference**, not ordinary one-shot text completion. At inference time, the host application should expose database metadata and SQL execution tools, then enforce the four-phase action protocol.
|
| 93 |
+
|
| 94 |
+
Minimal loading example:
|
| 95 |
+
|
| 96 |
+
```python
|
| 97 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 98 |
+
|
| 99 |
+
model_id = "AIJian/TrustSQL-8B"
|
| 100 |
+
|
| 101 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 102 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 103 |
+
model_id,
|
| 104 |
+
torch_dtype="auto",
|
| 105 |
+
device_map="auto",
|
| 106 |
+
trust_remote_code=True,
|
| 107 |
+
)
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
For the complete action schemas, prompts, training configuration, and evaluation pipeline, see the project repository:
|
| 111 |
+
|
| 112 |
+
`https://github.com/JaneEyre0530/TrustSQL`
|
| 113 |
+
|
| 114 |
+
## Important limitations
|
| 115 |
+
|
| 116 |
+
- Training and reported evaluations use SQLite-based benchmarks.
|
| 117 |
+
- Inference requires access to the target database or a compatible metadata/execution environment.
|
| 118 |
+
- The current implementation uses a fixed interaction budget; highly complex databases may benefit from adaptive horizons.
|
| 119 |
+
- The reported benchmark numbers are research results and should not be interpreted as a guarantee for production workloads.
|
| 120 |
+
|
| 121 |
+
## Citation
|
| 122 |
+
|
| 123 |
+
```bibtex
|
| 124 |
+
@article{jian2026trustsql,
|
| 125 |
+
title = {TRUST-SQL: Tool-Integrated Multi-Turn Reinforcement Learning for Text-to-SQL over Unknown Schemas},
|
| 126 |
+
author = {Jian, Ai and Zhang, Xiaoyun and Du, Wanrou and Ruan, Jingqing and Pei, Jiangbo and Zhang, Weipeng and Zeng, Ke and Cai, Xunliang},
|
| 127 |
+
journal = {arXiv preprint arXiv:2603.16448},
|
| 128 |
+
year = {2026},
|
| 129 |
+
url = {https://arxiv.org/abs/2603.16448}
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## License
|
| 134 |
+
|
| 135 |
+
The released model and dataset repositories are marked as Apache-2.0. The dataset may contain material derived from third-party benchmarks; users are responsible for complying with the original benchmark licenses and usage terms.
|
| 136 |
+
|
| 137 |
+
## Contact
|
| 138 |
+
|
| 139 |
+
For questions or feedback, please open an issue in the project repository or contact `jianai@bupt.edu.cn`.
|