ORANGE: An Online Reflection ANd GEneration framework with Domain Knowledge for Text-to-SQL

Yiwen Jiao, Tonghui Ren, Yuche Gao, Zhenying He, Yinan Jing, Kai Zhang, X. Sean WangarXiv 2025 · DOI

Introduction

ORANGE is a self-evolutionary framework designed to help Large Language Models (LLMs) master Text-to-SQL translation by building a database-specific "memory" from past interaction logs. By employing a novel "tuple-semantic tracking" method, ORANGE bridges the semantic gap between general LLM knowledge and specific database schemas. This approach has achieved state-of-the-art results on major benchmarks, including BIRD and SCIENCE.

Problem Statement: The Semantic Gap and Tuple-Semantic Shifts

While LLMs are proficient at writing SQL, they frequently encounter two major hurdles in domain-specific applications:

  1. The Semantic Gap: LLMs often lack knowledge of specific database conventions. For instance, a model might understand "district" generally but not realize that in a specific financial database, the column A2 represents districts while A3 represents regions.
  2. Tuple-Semantic Shifts: Logic errors often occur during complex operations like JOINs. When an "Atom" table is joined with a "Molecule" table, a single row in the result set no longer represents one molecule; it represents one atom within a molecule. Failure to recognize this shift leads to incorrect aggregations, such as overcounting molecules by counting rows.
Examples of semantic gaps and tuple-semantic shifts in Text-to-SQL tasks.

The ORANGE Framework

ORANGE (Online Reflection ANd GEneration) introduces a three-stage pipeline to transform translation logs into a reusable knowledge base:

  1. Knowledge Decomposition (The PARSER): Using a nested Chain-of-Thought (CoT) strategy, ORANGE breaks complex SQL into sub-components. It utilizes Tuple-Semantic Tracking to monitor how each operation (JOIN, Aggregation) changes the meaning of a single row in the result set.
  2. Knowledge Validation (The VALIDATOR): To ensure high-quality data, a probability-based filter calculates the likelihood that a generated knowledge unit is correct. Only high-confidence pairs are stored in long-term memory.
  3. Knowledge-Enhanced Translation (The CODER): When a new query is received, the system retrieves relevant "lessons" from memory to serve as in-context demonstrations, providing the LLM with a database-specific "cheat sheet."
The ORANGE pipeline: Knowledge Decomposition and Validation from system logs.

Evaluation and Key Results

The framework was evaluated on three major benchmarks: BIRD (large-scale, real-world databases), Spider (cross-domain), and SCIENCE (complex scientific domains).

  • State-of-the-Art Performance: On the BIRD benchmark, ORANGE achieved an Execution Accuracy (EX) of 65.12%, outperforming the strong CHESS baseline by 3.13%.
  • Handling Complexity: Accuracy on "Challenging" tasks in BIRD improved by 6.24% over baselines.
  • Domain Adaptability: On the SCIENCE benchmark, it reached an EX of 54.52%, demonstrating its ability to accumulate specialized scientific knowledge.
  • Model Agnostic: When paired with reasoning models like DeepSeek-V3, ORANGE reached 70.27% on BIRD.

Key Insights

  • Continuous Learning: ORANGE treats Text-to-SQL as an evolving process where the system becomes more intelligent as it is used within a specific domain.
  • Focus on the Tuple: Most semantic errors are logic-based rather than syntactic. By forcing the model to explain "tuple shifts," ORANGE creates more reliable training examples.
  • In-Domain Superiority: Experiments indicate that providing a few examples from the same database is significantly more effective than general reasoning prompts or cross-domain examples.

Limitations and Future Work

ORANGE currently faces a "cold-start" dependency, requiring an initial candidate SQL generator to begin building logs. Additionally, the online reflection process introduces some computational overhead. Future research will focus on refining the SQL-to-Text reflection quality and exploring alternative initialization techniques to mitigate the cold-start phase.

Summary updated

BibTeX
@misc{jiao2025orange,
  author = {Yiwen Jiao and Tonghui Ren and Yuche Gao and Zhenying He and Yinan Jing and Kai Zhang and X. Sean Wang},
  title = {{ORANGE: An Online Reflection ANd GEneration framework with Domain Knowledge for Text-to-SQL}},
  year = {2025},
  eprint = {2511.00985},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.00985},
}
Figure