Skip to main content

llama-index tools database integration

Project description

Database Tool

This tool connects to a database (using SQLAlchemy under the hood) and allows an Agent to query the database and get information about the tables.

Usage

This tool has more extensive example usage documented in a Jupyter notebook here.

Here's an example usage of the DatabaseToolSpec.

from llama_index.tools.database import DatabaseToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

db_tools = DatabaseToolSpec(
    scheme="postgresql",  # Database Scheme
    host="localhost",  # Database Host
    port="5432",  # Database Port
    user="postgres",  # Database User
    password="FakeExamplePassword",  # Database Password
    dbname="postgres",  # Database Name
)
agent = FunctionAgent(
    tools=db_tools.to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)

print(await agent.run("What tables does this database contain"))
print(await agent.run("Describe the first table"))
print(await agent.run("Retrieve the first row of that table"))

The tools available are:

list_tables: A tool to list the tables in the database schema describe_tables: A tool to describe the schema of a table load_data: A tool that accepts an SQL query and returns the result

This loader is designed to be used as a way to load data as a Tool in a Agent.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_database-0.5.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_tools_database-0.5.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_tools_database-0.5.0.tar.gz.

File metadata

  • Download URL: llama_index_tools_database-0.5.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_database-0.5.0.tar.gz
Algorithm Hash digest
SHA256 070531acef7b1d9b0a7d5f0cc3a640b3fbbfa3a7b80eb7ffb86d708015672b2a
MD5 5cb020250d88712bbac1a4e6ea8a70a4
BLAKE2b-256 3c42c1568c1818083b376b746cb615ace9fa944a0c9b3aee54099be4f469e21c

See more details on using hashes here.

File details

Details for the file llama_index_tools_database-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_tools_database-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_tools_database-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab1b048dee6961aacfa7e3ef612fbd71fa63c8073bb5cb3ae28bf4f732394ef0
MD5 74805882a3dad4cf4ec2bfa687b9ee4c
BLAKE2b-256 f920a02e9ed5d09463683e8a8df61e78899fb050837d2252e451a7b450f28588

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page