Skip to main content
This example shows how to use langchain-ibm watsonx.ai SQL Database Toolkit that uses Flight service.
Building Q&A systems of SQL databases requires executing model-generated SQL queries, which carries inherent security risks. Make sure that your database connection permissions are always scoped as narrowly as possible for your agent’s needs. This will mitigate, though not eliminate, the risks of building a model-driven system.

Overview

Integration details

Setup

To access langchain-ibm SQL Database toolkit you’ll need to create an IBM watsonx.ai account, get an API key, and install the langchain-ibm integration package.

Credentials

This cell defines the WML credentials required to work with watsonx SQL Database Toolkit. Action: Provide the IBM Cloud user API key. For details, see documentation.
Additionally you are able to pass additional secrets as an environment variable.

Installation

The LangChain IBM integration lives in the langchain-ibm package:

Instantiation

To set up the SQL Database toolkit, you must first instantiate the WatsonxSQLDatabase class, which retrieves necessary information from IBM watsonx.ai database connection assets via the Flight SQL client. For more details on creating the Database connection Asset programmatically see a watsonx.ai Python SDK documentation.
Alternatively, you can use Cloud Pak for Data credentials. For details, see watsonx.ai software setup. For certain requirements, there is an option to pass the IBM’s APIClient object into the WatsonxSQLDatabase class.
Finally, initialize the WatsonxSQLDatabaseToolkit.

Tools

Get all tools

Running .get_tools method, one can get all available tools as a list.
You can use the individual tools directly:

Use within an agent


API reference

For detailed documentation of all WatsonxSQLDatabaseToolkit features and configurations head to the API reference.