Watsonx SQL Database class for IBM watsonx.ai databases connection assets.
Uses Arrow Flight to interact with databases via watsonx.
WatsonxSQLDatabase(
self,
*,
connection_id: str,
schema: str,
project_id: str | None = None,
space_id: str | None = None,
url: str | None = None,
api_key: str | None = None,
apikey: str | None = None,
token: str | None = None,
password: str | None = None,
username: str | None = None,
instance_id: str | None = None,
version: str | None = None,
verify: str | bool | None = None,
watsonx_client: APIClient | None = None,
ignore_tables: list[str] | None = None,
include_tables: list[str] | None = None,
sample_rows_in_table_info: int = 3,
max_string_length: int = 300
)To use, you should have langchain_ibm python package installed,
and the environment variable WATSONX_API_KEY set with your API key, or pass
it as a named parameter api_key to the constructor.
pip install -U langchain-ibm
# or using uv
uv add langchain-ibm
export WATSONX_API_KEY="your-api-key"
apikey and WATSONX_APIKEY are deprecated and will be removed in
version 2.0.0. Use api_key and WATSONX_API_KEY instead.
from langchain_ibm.utilities.sql_database import WatsonxSQLDatabase
wx_sql_database = WatsonxSQLDatabase(
connection_id="<CONNECTION_ID>",
schema="<SCHEMA>",
url="<URL>",
project_id="<PROJECT_ID>",
api_key="<API_KEY>",
)ValueError - if some required credentials are missingRuntimeError - if no tables found in given schema| Name | Type | Description |
|---|---|---|
connection_id* | str | ID of db connection asset |
schema* | str | name of the database schema from which tables will be read |
project_id | str | None | Default: NoneID of project |
space_id | str | None | Default: NoneID of space |
url | str | None | Default: NoneURL to the Watson Machine Learning or CPD instance |
api_key | str | None | Default: NoneAPI key to the Watson Machine Learning or CPD instance |
apikey | str | None | Default: NoneAPI key to the Watson Machine Learning or CPD instance (deprecated) |
token | str | None | Default: Noneservice token, used in token authentication |
password | str | None | Default: Nonepassword to the CPD instance |
username | str | None | Default: Noneusername to the CPD instance |
instance_id | str | None | Default: Noneinstance_id of the CPD instance |
version | str | None | Default: Noneversion of the CPD instance |
verify | str | bool | None | Default: Nonecertificate verification flag |
watsonx_client | APIClient | None | Default: Noneinstance of |
ignore_tables | list[str] | None | Default: Nonelist of tables that will be ignored |
include_tables | list[str] | None | Default: Nonelist of tables that should be included |
sample_rows_in_table_info | int | Default: 3number of first rows to be added to the table info |
max_string_length | int | Default: 300max length of string |
| Name | Type |
|---|---|
| connection_id | str |
| schema | str |
| project_id | str | None |
| space_id | str | None |
| url | str | None |
| api_key | str | None |
| apikey | str | None |
| token | str | None |
| password | str | None |
| username | str | None |
| instance_id | str | None |
| version | str | None |
| verify | str | bool | None |
| watsonx_client | APIClient | None |
| ignore_tables | list[str] | None |
| include_tables | list[str] | None |
| sample_rows_in_table_info | int |
| max_string_length | int |
Get names of tables available.
Execute a SQL command and return a string representing the results.
Execute a SQL command and return a string representing the results.
If the statement throws an error, the error message is returned.
Get information about specified tables.
Get information about specified tables.
Return db context that you may want in agent prompt.