Skip to content

API Reference parrot.bots.database.toolkits.base

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.database.toolkits.base

View source

DatabaseToolkit — abstract base for all database toolkits.

Inherits from AbstractToolkit (auto-generates tools from public async methods) and adds the database-specific lifecycle: connect, search schema, execute queries, cache integration.

Alias AbstractToolkit

Re-exported from parrot.tools.toolkit.AbstractToolkit.

Alias CachePartition

Re-exported from parrot.bots.database.cache.CachePartition.

Class DatabaseToolkit

Abstract base class for all database toolkits.

Subclasses implement the two abstract methods (search_schema and execute_query). All public async methods are automatically converted to LLM-callable tools by AbstractToolkit._generate_tools().

Internal lifecycle methods (start, stop, cleanup, get_table_metadata, health_check) are hidden from the LLM via exclude_tools.

Parameter Type Default Description
dsn str
allowed_schemas Optional[List[str]] None
primary_schema Optional[str] None
tables Optional[List[str]] None
read_only bool True
cache_partition Optional[CachePartition] None
retry_config Optional[QueryRetryConfig] None
origin Optional[str] None
database_type str 'postgresql'
use_pool bool False
pool_params Optional[Dict[str, Any]] None
**kwargs Any {}

Attributes:

Attribute Type Description
tool_prefix str
exclude_tools tuple[str, ...]

Method DatabaseToolkit.start

Connect to the database using asyncdb.

start() -> None

Method DatabaseToolkit.stop

Close the database connection and release resources.

stop() -> None

Method DatabaseToolkit.cleanup

Alias for stop().

cleanup() -> None

Method DatabaseToolkit.health_check

Check if the database connection is alive.

health_check() -> bool

Returns: bool — True if the connection is healthy, False otherwise.

Method DatabaseToolkit.get_table_metadata

Retrieve cached table metadata for the given table.

get_table_metadata(schema_name: str, table_name: str) -> Optional[TableMetadata]

Parameter Type Default Description
schema_name str Schema that contains the table.
table_name str Name of the table.

Returns: Optional[TableMetadata] — TableMetadata if found, None otherwise.

Method DatabaseToolkit.search_schema

Search for tables/columns matching search_term.

search_schema(search_term: str, schema_name: Optional[str] = None, limit: int = 10) -> List[TableMetadata]

Parameter Type Default Description
search_term str Natural-language or keyword search.
schema_name Optional[str] None Restrict search to a specific schema.
limit int 10 Maximum results.

Returns: List[TableMetadata] — List of matching TableMetadata.

Method DatabaseToolkit.execute_query

Execute a query and return results.

execute_query(query: str, limit: int = 1000, timeout: int = 30) -> QueryExecutionResponse

Parameter Type Default Description
query str The query string (SQL, Flux, DSL, MQL, etc.).
limit int 1000 Maximum rows to return.
timeout int 30 Query timeout in seconds.

Returns: QueryExecutionResponse — QueryExecutionResponse with results or error info.

Class DatabaseToolkitConfig

Configuration passed to toolkit constructors.

Fields:

Field Type Default Description
dsn Optional[str] None Database connection string
allowed_schemas List[str]
primary_schema Optional[str] None
tables Optional[List[str]] None Optional list of tables to pre-warm the metadata cache during start(). Accepts 'schema.table' or 'table' (defaults to primary_schema). Missing/invalid entries are warned and skipped.
read_only bool True When True, execute_query() rejects any non-SELECT statement. When False, DML (INSERT/UPDATE/DELETE) is permitted but DDL (CREATE/ALTER/DROP/TRUNCATE/GRANT/REVOKE/RENAME) and multi-statements are always blocked, and UPDATE/DELETE require a WHERE clause.
database_type str 'postgresql'
origin Optional[str] None Schema-plane origin alias (FEAT-600); defaults to database_type
use_pool bool False When True, connect via asyncdb.AsyncPool (pool-based) instead of asyncdb.AsyncDB (single connection). Connections are acquired/released per query. Only supported by drivers that ship a <driver>Pool class (e.g. pg).
pool_params Optional[Dict[str, Any]] None Extra kwargs forwarded to the AsyncPool constructor when use_pool=True (e.g. {'min_size': 5, 'max_clients': 50}).

Alias QueryExecutionResponse

Re-exported from parrot.bots.database.models.QueryExecutionResponse.

Alias QueryRetryConfig

Re-exported from parrot.bots.database.retries.QueryRetryConfig.

Alias TableMetadata

Re-exported from parrot.bots.database.models.TableMetadata.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally