Table of Contents
Fetching ...

QueryGym: Step-by-Step Interaction with Relational Databases

Haritha Ananthakrishnan, Harsha Kokel, Kelsey Sikes, Debarun Bhattacharjya, Michael Katz, Shirin Sohrabi, Kavitha Srinivas

TL;DR

QueryGym reframes NL2Query as an engine-agnostic interactive task by casting it as a POMDP $(S,A,\Omega,T,R)$ where an agent must interact with the database through exploration actions and relational algebra operators to build a correct plan. It provides rich observations (schema, intermediate results, error feedback) and a mixed-action space that includes exploration probes and algebraic manipulations. The paper details environmental design, action/observation/transition/reward mechanics, and demonstrates a LangChain-based agent with a dedicated demonstration plan. This framework supports engine-agnostic research, data exploration, error remediation, and RL for query planning, with broad benchmark compatibility.

Abstract

We introduce QueryGym, an interactive environment for building, testing, and evaluating LLM-based query planning agents. Existing frameworks often tie agents to specific query language dialects or obscure their reasoning; QueryGym instead requires agents to construct explicit sequences of relational algebra operations, ensuring engine-agnostic evaluation and transparent step-by-step planning. The environment is implemented as a Gymnasium interface that supplies observations -- including schema details, intermediate results, and execution feedback -- and receives actions that represent database exploration (e.g., previewing tables, sampling column values, retrieving unique values) as well as relational algebra operations (e.g., filter, project, join). We detail the motivation and the design of the environment. In the demo, we showcase the utility of the environment by contrasting it with contemporary LLMs that query databases. QueryGym serves as a practical testbed for research in error remediation, transparency, and reinforcement learning for query generation. For the associated demo, see https://ibm.biz/QueryGym.

QueryGym: Step-by-Step Interaction with Relational Databases

TL;DR

QueryGym reframes NL2Query as an engine-agnostic interactive task by casting it as a POMDP where an agent must interact with the database through exploration actions and relational algebra operators to build a correct plan. It provides rich observations (schema, intermediate results, error feedback) and a mixed-action space that includes exploration probes and algebraic manipulations. The paper details environmental design, action/observation/transition/reward mechanics, and demonstrates a LangChain-based agent with a dedicated demonstration plan. This framework supports engine-agnostic research, data exploration, error remediation, and RL for query planning, with broad benchmark compatibility.

Abstract

We introduce QueryGym, an interactive environment for building, testing, and evaluating LLM-based query planning agents. Existing frameworks often tie agents to specific query language dialects or obscure their reasoning; QueryGym instead requires agents to construct explicit sequences of relational algebra operations, ensuring engine-agnostic evaluation and transparent step-by-step planning. The environment is implemented as a Gymnasium interface that supplies observations -- including schema details, intermediate results, and execution feedback -- and receives actions that represent database exploration (e.g., previewing tables, sampling column values, retrieving unique values) as well as relational algebra operations (e.g., filter, project, join). We detail the motivation and the design of the environment. In the demo, we showcase the utility of the environment by contrasting it with contemporary LLMs that query databases. QueryGym serves as a practical testbed for research in error remediation, transparency, and reinforcement learning for query generation. For the associated demo, see https://ibm.biz/QueryGym.

Paper Structure

This paper contains 16 sections, 1 figure.

Figures (1)

  • Figure 1: Sample trajectory in QueryGym, an interactive environment for query planning agents.