Google Gen AI Toolbox: A Python Library for SQL Databases

Janvi Kumari Last Updated : 27 Mar, 2025
10 min read

Google has introduced the Google Gen AI Toolbox for Databases, an open-source Python library designed to simplify database interaction with GenAI. By converting natural language queries into optimized SQL commands, the toolbox eliminates the complexities of SQL, making data retrieval more intuitive and accessible for both developers and non-technical users. As part of its public beta launch, Google has integrated Google GenAI tools with LangChain, to enhance tool management. This collaboration enables seamless AI-driven database operations, improving efficiency and automation in data workflows. This article explores the features, benefits, and setup process of the Google Gen AI Toolbox, highlighting its integration with LangChain and how it simplifies AI-powered database interactions.

The Need for AI-driven SQL Querying

SQL has been the backbone of database management for decades. However, writing complex queries requires expertise and can be time-consuming. The Gen AI Toolbox eliminates this barrier by enabling users to interact with databases using plain language, allowing for seamless and efficient data retrieval.

Also Read: SQL: A Full Fledged Guide from Basics to Advance Level

What is Google Gen AI Toolbox?

The Gen AI Toolbox enables seamless integration between AI agents and SQL databases, ensuring secure access, scalability, and observability while streamlining the creation and management of AI-powered tools. Currently, it supports PostgreSQL, MySQL, AlloyDB, Spanner, and Cloud SQL, with opportunities for further expansion beyond Google Cloud.

The Toolbox enhances how GenAI tools interact with data by serving as an intermediary between the application’s orchestration layer and databases. This setup accelerates development, improves security, and enhances production-quality AI tools.

Key Features of Gen AI Toolbox

The Gen AI Toolbox for Databases is designed to make AI-powered database interaction seamless and efficient. It simplifies query generation, enhances accessibility for non-technical users, and ensures smooth integration with existing systems. Here are some key features that make it a powerful tool:

  • Ask in Plain English: Users can input queries like “Show me the top 10 customers by sales”, and the toolbox generates the corresponding SQL command.
  • Empowering Non-Experts: Business analysts and non-technical users can extract insights without needing SQL expertise.
  • Plug & Play: Built as a Python library, it integrates smoothly into existing applications and AI models.
  • Flexible & Open-Source: Developers can customize and extend its functionality to suit unique needs.
  • Optimized for Production: Works with PostgreSQL, MySQL, AlloyDB, Spanner, and Cloud SQL, ensuring broad compatibility.
  • Simplified Management: Acts as a central AI layer, streamlining updates, maintenance, and security.

Components of Gen AI Toolbox for Databases

Google’s Gen AI Toolbox consists of two primary components:

  1. A server that defines tools for application usage.
  2. A client that interacts with the server to integrate these tools into orchestration frameworks.
Components of Google Gen AI Toolbox

How the Gen AI Toolbox Works

At its core, the Gen AI Toolbox leverages state-of-the-art LLMs to understand and translate natural language queries into SQL commands. The process involves:

  1. Schema Training: The library ingests database schemas, sample queries, and documentation to build an internal model of the database’s structure.
  2. Query Generation: When a user inputs a natural language request, the toolbox processes the query and generates a corresponding SQL statement.
  3. Execution & Feedback: The generated SQL can be executed directly on the connected database, with feedback mechanisms to refine query accuracy over time.

This streamlined approach significantly reduces the need for manual query crafting and paves the way for more intuitive data exploration.

Advantages of Using Google’s Gen AI Toolbox

The Google GenAI Toolbox enhances database interaction by automating SQL query generation, simplifying development, and integrating seamlessly with modern AI frameworks. Here are the key advantages:

  • Accelerated Insights & Broader Accessibility: By automating SQL queries, organizations can extract and analyze data faster. Non-technical users can interact with databases easily, fostering a data-driven culture.
  • Seamless AI Integration & Deployment: Designed to work with frameworks like LangChain, the toolbox enables sophisticated, agent-driven workflows. It supports both local and cloud environments, ensuring flexible deployment.
  • Simplified Development: Reduces boilerplate code and streamlines integration across multiple AI agents.
  • Optimized Performance & Scalability: Features database connectors and connection pooling for efficient resource management.
  • Zero Downtime Deployment: A configuration-driven approach allows seamless updates without service interruptions.
  • Enhanced Security: Supports OAuth2 and OpenID Connect (OIDC) to control access to tools and data securely.
  • End-to-End Observability: Integration with OpenTelemetry enables real-time logging, metrics, and tracing for better monitoring and troubleshooting.

By combining automation, flexibility, and security, the GenAI Toolbox empowers both developers and data analysts to work more efficiently with databases.

Integration with LangChain

LangChain, a widely used developer framework for LLM applications, is fully compatible with Toolbox.  With LangChain, developers can leverage LLMs such as Gemini on Vertex AI to build sophisticated agentic workflows.

LangGraph extends LangChain’s functionality by offering state management, coordination, and workflow structuring for multi-actor AI applications. This framework ensures precise tool execution, reliable responses, and controlled tool interactions, making it an ideal partner for Toolbox in managing AI agent workflows.

Harrison Chase, CEO of LangChain, highlighted the significance of this integration, stating: “The integration of Gen AI Toolbox for Databases with the LangChain ecosystem is a boon for all developers. In particular, the tight integration between Toolbox and LangGraph will allow developers to build more reliable agents than ever before.”

Setting Up Toolbox Locally with Python, PostgreSQL, and LangGraph

To use the full potential of the GenAI Toolbox, setting it up locally with Python, PostgreSQL, and LangGraph is essential. This setup enables seamless database interaction, AI-driven query generation, and smooth integration with existing applications. Follow the steps below to get started.

Prerequisites

Before beginning, ensure that the following are installed on your system:

  1. Python 3.9+: Install Python along with pip and venv for dependency management.
  2. PostgreSQL 16+: Install PostgreSQL along with the psql client.
  3. LangChain Chat Model Setup: You need one of the following packages installed based on your model preference:
  • langchain-vertexai
  • langchain-google-genai
  • langchain-anthropic

Step 1: Set Up Your Database

In this step, we will create a PostgreSQL database, set up authentication, and insert some sample data.

1.1 Connect to PostgreSQL

First, connect to your PostgreSQL server using the following command:

psql -h 127.0.0.1 -U postgres

Here, postgres is the default superuser.

1.2 Create a New Database and User

For security, create a new user specifically for Toolbox and assign it a new database:

CREATE USER bookstore_user WITH PASSWORD 'my-password';

CREATE DATABASE bookstore_db;
GRANT ALL PRIVILEGES ON DATABASE bookstore_db TO bookstore_user;

ALTER DATABASE bookstore_db OWNER TO bookstore_user;
creating new database

This ensures that bookstore_user has full access to bookstore_db.

1.3 Exit and Reconnect as the New User

Exit the current session:

\q

Now, reconnect using the new user:

psql -h 127.0.0.1 -U bookstore_user -d bookstore_db
login bookstore

1.4 Create a Books Table

We will now create a books table to store book details.

CREATE TABLE books(
  id           SERIAL PRIMARY KEY,
  title        VARCHAR NOT NULL,
  author       VARCHAR NOT NULL,
  genre        VARCHAR NOT NULL,
  price        DECIMAL(10,2) NOT NULL,
  stock        INTEGER NOT NULL,
  published_on DATE NOT NULL
);

This table contains book metadata like title, author, genre, price, stock availability, and publication date.

1.5 Insert Sample Data

Add some books to the database:

INSERT INTO books(title, author, genre, price, stock, published_on)
VALUES 
  ('The Great Gatsby', 'F. Scott Fitzgerald', 'Classic', 12.99, 5, '1925-04-10'),
  ('1984', 'George Orwell', 'Dystopian', 9.99, 8, '1949-06-08'),
  ('To Kill a Mockingbird', 'Harper Lee', 'Fiction', 14.50, 3, '1960-07-11'),
  ('The Hobbit', 'J.R.R. Tolkien', 'Fantasy', 15.00, 6, '1937-09-21'),
  ('Sapiens', 'Yuval Noah Harari', 'Non-Fiction', 20.00, 10, '2011-02-10');
Google Gen AI Toolbox: A Python Library for SQL Databases

Exit the session using:

\q

Step 2: Install and Configure the Gen AI Toolbox

Now, we will install Toolbox and configure it to interact with our PostgreSQL database.

2.1 Download and Install the Toolbox

Download the latest version of Toolbox:

export OS="linux/amd64" # Adjust based on your OS
curl -O https://storage.googleapis.com/genai-toolbox/v0.2.0/$OS/toolbox
chmod +x toolbox

This command downloads the appropriate version of Toolbox and makes it executable.

2.2 Configure the Toolbox

Create a tools.yaml file to define database connections and SQL queries.

Define Database Connection

sources:
my-pg-source:
kind: postgres
host: 127.0.0.1
port: 5432
database: bookstore_db
user: bookstore_user
password: my-password

This connects Toolbox to our PostgreSQL database.

Define Query-Based Tools

We define SQL queries for various operations:

tools:
search-books-by-title:
kind: postgres-sql
source: my-pg-source
description: Search for books based on title.
parameters:
- name: title
type: string
description: The title of the book.
statement: |
SELECT * FROM books
WHERE title ILIKE '%' || $1 || '%';

search-books-by-author:
kind: postgres-sql
source: my-pg-source
description: Search for books by a specific author.
parameters:
- name: author
type: string
description: The name of the author.
statement: |
SELECT * FROM books
WHERE author ILIKE '%' || $1 || '%';

check-book-stock:
kind: postgres-sql
source: my-pg-source
description: Check stock availability of a book.
parameters:
- name: title
type: string
description: The title of the book.
statement: |
SELECT title, stock
FROM books
WHERE title ILIKE '%' || $1 || '%';

update-book-stock:
kind: postgres-sql
source: my-pg-source
description: Update stock after a purchase.
parameters:
- name: book_id
type: integer
description: The ID of the book.
- name: quantity
type: integer
description: The number of books purchased.
statement: |
UPDATE books
SET stock = stock - $2
WHERE id = $1
AND stock >= $2;

2.3 Run the Toolbox Server

Start the Toolbox server using the configuration file:

./toolbox --tools_file "tools.yaml"
Google Gen AI Toolbox: A Python Library for SQL Databases

Step 3: Connecting an Agent to Toolbox

Now, we set up a LangGraph agent to interact with Toolbox.

3.1 Install Dependencies

To connect a LangGraph agent, install the required dependencies:

pip install toolbox-langchain
pip install langgraph langchain-google-vertexai
# Optional:
# pip install langchain-google-genai
# pip install langchain-anthropic

3.2 Create a LangGraph Agent

Create a Python script named langgraph_hotel_agent.py and include the following code:

import asyncio
from langgraph.prebuilt import create_react_agent
from langchain_google_genai import ChatGoogleGenerativeAI
from langgraph.checkpoint.memory import MemorySaver
from toolbox_langchain import ToolboxClient
import time

prompt = """
You're a helpful bookstore assistant. You help users search for books by title and author, check stock availability, and update stock after purchases. Always mention book IDs when performing any searches.
"""

queries = [
"Find books by George Orwell.",
"Do you have 'The Hobbit' in stock?",
"I want to buy 2 copies of 'Sapiens'.",
]

def main():
# Replace ChatVertexAI with ChatGoogleGenerativeAI (Gemini)
model = ChatGoogleGenerativeAI(
model="gemini-1.5-flash",
temperature=0,
max_retries=5,
retry_min_seconds=5,
retry_max_seconds=30
)

# Load tools from Toolbox
client = ToolboxClient("http://127.0.0.1:5000")
tools = client.load_toolset()

agent = create_react_agent(model, tools, checkpointer=MemorySaver())
config = {"configurable": {"thread_id": "thread-1"}}

for query in queries:
inputs = {"messages": [("user", prompt + query)]}
try:
response = agent.invoke(inputs, stream_mode="values", config=config)
print(response["messages"][-1].content)
except Exception as e:
print(f"Error processing query '{query}': {e}")
# Wait before trying the next query
time.sleep(10)

main()

3.3 Run the Agent

Execute the script to interact with the Toolbox:

python langgraph_hotel_agent.py

Output:

Google Gen AI Toolbox output

From the output, we can see that the script langgraph_bookstore_agent.py manages bookstore inventory by listing books, confirming availability, and updating stock. The stock of “Sapiens” decreases across runs (from 8 to 6), indicating persistent storage or database updates.

This setup provides a quick and efficient way to get started with Google’s Gen AI Toolbox locally using Python, PostgreSQL, and LangGraph. By following these steps, you can configure a PostgreSQL database, define SQL-based tools, and integrate them with a LangGraph agent to manage your store’s inventory, seamlessly.

Challenges in Using the Gen AI Toolbox

Developers working with AI agents often face multiple challenges when integrating tools, frameworks, and databases. The same exists when working with Google’s Gen AI Toolbox as well. Some of these challenges include:

  • Scaling tool management: Managing AI tools requires extensive, repetitive coding and modifications across various applications, hindering consistency and integration.
  • Complex database connections: Configuring databases for optimal performance at scale demands connection pooling, caching, and efficient resource management.
  • Security vulnerabilities: Ensuring secure access between GenAI models and sensitive data requires robust authentication mechanisms, increasing complexity and risk.
  • Inflexible tool updates: The process of adding or updating tools often necessitates complete application redeployment, leading to potential downtime.
  • Limited workflow observability: Existing solutions lack built-in monitoring and troubleshooting support, making it difficult to gain insights into AI workflows.

Alternative AI Solutions for SQL Query Generation

While Google’s Gen AI Toolbox offers an innovative approach to AI-powered database interaction, several other tools also simplify SQL querying using generative AI. These solutions enable users to retrieve data effortlessly without requiring deep SQL expertise.

Here are some notable alternatives:

  • SQLAI.ai: An AI-powered tool that can generate, optimize, fix, simplify, and explain SQL queries. It supports multiple database systems, allowing non-experts to extract insights quickly.
  • Text2SQL.ai: Converts everyday language into SQL queries, supporting various database engines to streamline query generation.
  • QueryGPT by Uber: Uses large language models to generate SQL queries from natural language prompts, significantly reducing query-writing time.
  • SQLPilot: Uses a knowledge base to generate SQL queries and supports user customization, including OpenAI key integration.
  • BlazeSQL: A chatbot-powered SQL AI tool that connects directly to databases, offering instant SQL generation, dashboarding, and security-focused features.
  • Microsoft Copilot in Azure SQL: Integrated within the Azure portal, enabling natural language prompts for T-SQL query generation.
  • NL2SQL Frameworks: Research and commercial implementations that convert natural language into SQL, catering to specific industries and use cases.

These alternatives, like Google’s Gen AI Toolbox, aim to bridge the gap between AI and SQL by making database interactions more intuitive and accessible. Depending on specific use cases, organizations can choose a tool that best aligns with their database infrastructure and workflow needs.

Conclusion

Google’s Gen AI Toolbox simplifies SQL querying with natural language processing, making database interactions intuitive for both developers and non-technical users. With LangChain integration and support for major SQL databases, it ensures secure, scalable, and efficient AI-driven data retrieval. By addressing challenges like scalability, security, and workflow management, the toolbox streamlines AI adoption in database operations. Looking ahead, its continued evolution promises smarter, more accessible AI-powered data solutions.

Frequently Asked Questions

Q1. What is the Google Gen AI Toolbox?

A. The Google Gen AI Toolbox is an open-source Python library that enables AI-powered SQL querying. It allows users to retrieve database information using natural language instead of writing complex SQL commands.

Q2. Which databases are supported by the Gen AI Toolbox?

A. The toolbox currently supports PostgreSQL, MySQL, AlloyDB, Spanner, and Cloud SQL, with potential expansion to other databases in the future.

Q3. Do I need to know SQL to use the Gen AI Toolbox?

A. No, the toolbox is designed for both developers and non-technical users. It translates plain language queries into optimized SQL commands, making database interactions intuitive.

Q4. How does the Gen AI Toolbox integrate with LangChain?

A. The toolbox seamlessly integrates with LangChain and LangGraph, enabling AI agents to query databases and process structured data efficiently within AI-driven applications.

Q5. Is the Gen AI Toolbox open-source?

A. Yes, the toolbox is open-source, allowing developers to customize, extend, and integrate it with their existing applications and workflows.

Q6. How secure is the Gen AI Toolbox?

A. It supports OAuth2 and OpenID Connect (OIDC) for secure access control and integrates with OpenTelemetry for monitoring and observability.

Q7. Can I use the Gen AI Toolbox in a production environment?

A. Yes, the toolbox is optimized for production workloads, featuring connection pooling, caching, and zero-downtime deployments for seamless updates.

Hi, I am Janvi, a passionate data science enthusiast currently working at Analytics Vidhya. My journey into the world of data began with a deep curiosity about how we can extract meaningful insights from complex datasets.

Login to continue reading and enjoy expert-curated content.

Responses From Readers

Clear

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details