DB tool
By using the DB tool, you can connect your database and provide the model with valuable context, improving the quality of interactions. Learn more about the tool concept here
Here’s how you can do it:
Database support and configuration
Supported DB's
Ensure that your database is one of the following supported types:
- PostgreSQL (dialect:
postgresql
)- MySQL and MariaDB (dialect:
mysql
)- Oracle (dialect:
oracle
)- Microsoft SQL Server (dialect:
mssql
)- BigQuery
Using the UI
Step 1: Add the DB tool
Click on the "+ Tool" button, and then SQL DB tool" start setting up the database connection.
Step 2: Configure the tool
- Assign a meaningful name to the tool. This name will help the model understand the context in which the data will be used.
- Add a description: Provide a thorough description of the database and its use. This information assists the model in contextualizing the data and influences the prompts generated by the system.
- Database Selection and Connection: Identify and connect to your chosen database by providing the requisite details:
- For BigQuery:
- Specify your
BigQuery project
. - Input the
BigQuery dataset
you intend to query. - Input your
GCP service account
information for credential validation (in a JSON format).
- Specify your
- For Other Database Types:
- Construct your Database URL in the format:
dialect://username:password@host:port/database
. Ensure you replace the placeholders with actual values specific to your database credentials and connection information.
- Construct your Database URL in the format:
- For BigQuery:

Using the SDK
To create a DB tool using the SDK, use the code snippet below as a guide and include the following details:
-
Assign a meaningful name to your tool. The chosen name will aid the model in recognizing the context for which the data is intended.
-
Provide a comprehensive description of the tool. Elaborate on the database’s purpose and its operational context. This description helps the model to contextualize the data, thereby enhancing the relevance and accuracy of the system-generated prompts
-
Connection configuration:
- For BQ db type: specify your
project_id
,dataset_id
andservice account
in a JSON format - For Other Database Types: Specify the connection string in the given format:
dialect://username:password@host:port/database
. Make sure to substitute the placeholders with your actual database credentials and details.
- For BQ db type: specify your
Create BQ DB tool example:
from superwise_api.models import ToolDef, ToolConfigBigQuery, ToolType, ApplicationConfigPayload
bigquery_tool = ToolDef(
name="My tool name",
description="Describe this tool for the LLM",
config=ToolConfigBigQuery(
type=ToolType.SQL_DATABASE_BIGQUERY,
project_id="project_id",
dataset_id="dataset_id",
service_account={SERVICE_ACCOUNT_JSON},
)
)
update_app_tools_payload = ApplicationConfigPayload(model=model, prompt=None, tools=[bigquery_tool],
name="My application name")
updated_app = sw.application.put(str(app.id), update_app_tools_payload)
Create all other DB types tool example code:
from superwise_api.models import ToolDef, ToolType, ApplicationConfigPayload, \
ToolConfigSQLDatabasePostgres
postgres_tool = ToolDef(
name="My tool name",
description="Describe this tool for the LLM",
config=ToolConfigSQLDatabasePostgres(
type=ToolType.SQL_DATABASE_POSTGRES,
connection_string="[connection_string]",
)
)
update_app_tools_payload = ApplicationConfigPayload(model=model, prompt=None, tools=[postgres_tool],
name="My application name")
updated_app = sw.application.put(str(app.id), update_app_tools_payload)
Test connection
SWE offers you the option to check the connection to your resources in any given time by using the following API call
Example: Test connection to BQ
POST app.superwise.ai/v1/applications/test-tool-connection
{
"type": "BigQuery",
"project_id": "blattnertechdemo",
"dataset_id": "AIRPORT",
"service_account": {
"type": "service_account",
"project_id": "",
"private_key_id": "",
"private_key":"",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url":"",
"universe_domain":""
}
Updated about 1 year ago