Skip to content

API Reference parrot.tools.dataset_manager.sources.sql

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

parrot.tools.dataset_manager.sources.sql

View source

SQLQuerySource — user-provided SQL with {param} interpolation.

Executes an arbitrary SQL template against any AsyncDB-supported driver. All {param} placeholders are validated and safely escaped at fetch() time.

Alias DataSource

Re-exported from parrot.tools.dataset_manager.sources.base.DataSource.

Class SQLQuerySource

DataSource backed by a user-provided SQL template with {param} interpolation.

SQL can contain placeholders like {start_date}, {ticker} etc. All placeholders are validated and escaped at fetch() time before execution.

Parameter Type Default Description
sql str SQL template string with optional {param} placeholders.
driver str AsyncDB driver name (pg, mysql, bigquery, etc.).
dsn Optional[str] None Optional DSN string. For PostgreSQL drivers, resolved via get_default_credentials(driver) when None.
credentials Optional[Dict[str, Any]] None Optional credentials dict for the database connection. Used when dsn is not set (e.g. BigQuery needs a credentials path + project_id, not a DSN). When both dsn and credentials are None, defaults are resolved from navconfig for the driver (mirrors TableSource behavior).
cache_ttl int 3600 Cache TTL in seconds. Defaults to 3600.

Attributes:

Attribute Type Description
cache_key str Stable Redis cache key for this source.

Method SQLQuerySource.describe

Human-readable description for the LLM.

describe() -> str

Returns: str — Description string showing the driver and a truncated SQL preview.

Method SQLQuerySource.prefetch_schema

Return empty dict — schema only available after first fetch.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Empty dict.

Method SQLQuerySource.fetch

Execute the SQL template and return a DataFrame.

Validates that all {param} placeholders are present in params, escapes values to prevent SQL injection, interpolates the SQL, and executes it via AsyncDB.

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} Values for each {param} placeholder in the SQL template.

Returns: pd.DataFrame — DataFrame with the query results.

Raises:

  • ValueError — If required params are missing.
  • RuntimeError — If the query fails or does not return a DataFrame.

Alias get_default_credentials

Re-exported from parrot.interfaces.database.get_default_credentials.

Alias lazy_import

Re-exported from parrot._imports.lazy_import.

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