Table of Contents
Fetching ...

Towards Optimizing SQL Generation via LLM Routing

Mohammadhossein Malekpour, Nour Shaheen, Foutse Khomh, Amine Mhedhbi

TL;DR

This paper introduces the first LLM routing approach for Text-to-SQL, which dynamically selects the most cost-effective LLM capable of generating accurate SQL for each query.

Abstract

Text-to-SQL enables users to interact with databases through natural language, simplifying access to structured data. Although highly capable large language models (LLMs) achieve strong accuracy for complex queries, they incur unnecessary latency and dollar cost for simpler ones. In this paper, we introduce the first LLM routing approach for Text-to-SQL, which dynamically selects the most cost-effective LLM capable of generating accurate SQL for each query. We present two routing strategies (score- and classification-based) that achieve accuracy comparable to the most capable LLM while reducing costs. We design the routers for ease of training and efficient inference. In our experiments, we highlight a practical and explainable accuracy-cost trade-off on the BIRD dataset.

Towards Optimizing SQL Generation via LLM Routing

TL;DR

This paper introduces the first LLM routing approach for Text-to-SQL, which dynamically selects the most cost-effective LLM capable of generating accurate SQL for each query.

Abstract

Text-to-SQL enables users to interact with databases through natural language, simplifying access to structured data. Although highly capable large language models (LLMs) achieve strong accuracy for complex queries, they incur unnecessary latency and dollar cost for simpler ones. In this paper, we introduce the first LLM routing approach for Text-to-SQL, which dynamically selects the most cost-effective LLM capable of generating accurate SQL for each query. We present two routing strategies (score- and classification-based) that achieve accuracy comparable to the most capable LLM while reducing costs. We design the routers for ease of training and efficient inference. In our experiments, we highlight a practical and explainable accuracy-cost trade-off on the BIRD dataset.

Paper Structure

This paper contains 15 sections, 5 figures, 2 tables.

Figures (5)

  • Figure 1: A multi-stage Text-to-SQL pipeline with an LLM router within the generation stage.
  • Figure 2: Distribution of Failure and Correct Cases across gpt-4o, gpt-4o-mini, and llama3.1:8b-instruct-q4_0
  • Figure 3: Execution Accuracy for a score-based router with different None routing strategies.
  • Figure 4: Effect of varying $K$ on execution accuracy and on model distribution for score-based router.
  • Figure 5: Effect of varying $\alpha$ on execution accuracy and on model distribution for score-based router.