Skip to content

API Reference parrot.tools.databasequery.tool

github-actions[bot] edited this page Nov 5, 2026 · 4 revisions

parrot.tools.databasequery.tool

View source

Database Query Tool migrated to use AbstractTool framework.

Alias AbstractTool

Re-exported from parrot.tools.abstract.AbstractTool.

Class DatabaseQueryArgs

Arguments schema for DatabaseQueryTool.

Fields:

Field Type Default Description
driver str Database driver to use. Supported drivers:\nSQL-based: 'pg' (PostgreSQL), 'mysql', 'bigquery', 'sqlite', 'oracle', 'mssql' (Microsoft SQL Server), 'clickhouse', 'duckdb'\nTime-series: 'influx' (InfluxDB - uses Flux query language)\nDocument-based: 'mongo' (MongoDB), 'atlas' (MongoDB Atlas), 'documentdb' (AWS DocumentDB)\nNote: Query syntax must match the driver's query language.
query Union[str, Dict[str, Any]] Query to execute for data retrieval. Query syntax depends on the driver:\n\nSQL drivers (pg, mysql, bigquery, etc.):\n Use SQL SELECT statements, e.g.: SELECT * FROM users WHERE age > 25\n\nInfluxDB (influx):\n Use Flux query language, e.g.: from(bucket:"my-bucket") |> range(start: -1h)\n\nMongoDB/DocumentDB (mongo, atlas, documentdb):\n Provide the MongoDB query filter as JSON.\n The collection_name must be specified in the \
credentials Optional[Dict[str, Any]] None Dictionary containing database connection credentials (optional if defaults available).\n\nFor SQL databases:\n {'host': 'localhost', 'port': 5432, 'database': 'mydb', 'user': 'admin', 'password': 'secret'}\n\nFor MongoDB/DocumentDB (mongo, atlas, documentdb):\n REQUIRED: 'collection_name' - The collection to query\n Example: {\n 'host': 'cluster.docdb.amazonaws.com',\n 'port': 27017,\n 'database': 'mydb',\n 'collection_name': 'users', # REQUIRED for mongo-based drivers\n 'username': 'admin',\n 'password': 'secret',\n 'ssl': True, # For DocumentDB\n 'tlsCAFile': '/path/to/cert.pem' # For DocumentDB\n }
dsn Optional[str] None Optional DSN string for database connection (overrides credentials if provided)
output_format Literal['pandas', 'json', 'native', 'arrow'] Output format for query results: 'pandas' for DataFrame, 'json' for JSON string, 'native' for native format, 'arrow' for Apache Arrow format
query_timeout int Query timeout in seconds (default: 300)
max_rows int Maximum number of rows to return (default: 10000)

Method DatabaseQueryArgs.validate_timeout

validate_timeout(v)

Parameter Type Default Description
v

Method DatabaseQueryArgs.validate_max_rows

validate_max_rows(v)

Parameter Type Default Description
v

Method DatabaseQueryArgs.validate_driver

validate_driver(v)

Parameter Type Default Description
v

Method DatabaseQueryArgs.validate_credentials

Ensure credentials is either None, a dict, or a DSN string.

validate_credentials(v)

Parameter Type Default Description
v

Class DatabaseQueryTool

Multi-language Database Query Tool for executing queries across multiple database systems.

This tool can execute SELECT queries on various databases including BigQuery, PostgreSQL, MySQL, InfluxDB, SQLite, Oracle, and others supported by asyncdb library.

Supports multiple query languages:

  • SQL: PostgreSQL (pg), MySQL, BigQuery, SQLite, Oracle, MS SQL Server (mssql), ClickHouse, DuckDB
  • Flux: InfluxDB (influx) - time-series database with Flux query language
  • DocumentDB: DocumentDB (documentdb) - document-oriented database

DRIVER REFERENCE:

  • 'pg' or 'postgres' or 'postgresql' → PostgreSQL
  • 'mysql' or 'mariadb' → MySQL/MariaDB
  • 'bigquery' or 'bq' → Google BigQuery
  • 'mssql' or 'sqlserver' → Microsoft SQL Server
  • 'influx' or 'influxdb' → InfluxDB (uses Flux, not SQL)
  • 'sqlite' → SQLite
  • 'oracle' → Oracle Database
  • 'clickhouse' → ClickHouse
  • 'duckdb' → DuckDB
  • 'documentdb' → DocumentDB (MongoDB-compatible)
  • 'elastic' → Elasticsearch (Elasticsearch/OpenSearch)

QUERY LANGUAGE EXAMPLES:

SQL (pg, mysql, bigquery, etc.): SELECT column1, column2 FROM table WHERE condition

Flux (influx): from(bucket: "my-bucket") |> range(start: -12h) |> filter(fn: (r) => r["_measurement"] == "temperature") |> filter(fn: (r) => r["location"] == "room1")

IMPORTANT: This tool is designed for data retrieval and analysis queries (SELECT statements). It should NOT be used for:

  • DDL operations (CREATE, ALTER, DROP tables/schemas)
  • DML operations (INSERT, UPDATE, DELETE data)
  • Administrative operations (GRANT, REVOKE permissions)
  • Database structure modifications

Use this tool for:

  • Data exploration and analysis
  • Generating reports from existing data
  • Aggregating and summarizing information
  • Filtering and searching database records
  • Joining data from multiple tables for analysis
Parameter Type Default Description
**kwargs {} Forwarded to AbstractTool.__init__.

Method DatabaseQueryTool.get_supported_drivers

Get list of supported database drivers.

get_supported_drivers() -> List[str]

Returns: List[str]

Method DatabaseQueryTool.test_connection

Test database connection.

test_connection(driver: str, credentials: Optional[Dict[str, Any]] = None) -> Dict[str, Any]

Parameter Type Default Description
driver str Database driver to test
credentials Optional[Dict[str, Any]] None Optional credentials to use

Returns: Dict[str, Any] — Dictionary with connection test results

Method DatabaseQueryTool.save_query_result

Save query result to file.

save_query_result(result: Union[pd.DataFrame, str], filename: Optional[str] = None, file_format: str = 'csv') -> Dict[str, Any]

Parameter Type Default Description
result Union[pd.DataFrame, str] Query result to save
filename Optional[str] None Optional filename
file_format str 'csv' File format ('csv', 'json', 'excel')

Returns: Dict[str, Any] — Dictionary with file information

Class DriverInfo

Driver metadata wrapper preserved for back-compat (FEAT-105).

Pre-FEAT-105, this class lived in parrot_tools.databasequery and exposed classmethods used by external plugins. The migration moved its internals to module-level helpers (_DRIVER_TO_QUERY_LANGUAGE, _get_query_language, normalize_driver). This thin wrapper restores the legacy surface so the parrot_tools.databasequery shim keeps working.

Attributes:

Attribute Type Description
DRIVER_MAP Dict[str, QueryLanguage]

Method DriverInfo.normalize_driver

Normalize a driver alias to its canonical name.

normalize_driver(driver: str) -> str

Parameter Type Default Description
driver str

Returns: str

Method DriverInfo.get_query_language

Return the QueryLanguage for a driver alias or canonical name.

get_query_language(driver: str) -> QueryLanguage

Parameter Type Default Description
driver str

Returns: QueryLanguage

Alias QueryLanguage

Re-exported from parrot.security.QueryLanguage.

Alias QueryValidator

Re-exported from parrot.security.QueryValidator.

Alias normalize_driver

Re-exported from parrot.tools.databasequery.sources.normalize_driver.

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