Skip to content

API Reference parrot.tools.dataset_manager.sources.base

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

parrot.tools.dataset_manager.sources.base

View source

DataSource abstract base class.

A DataSource is a reference to data. It knows how to:

  • prefetch_schema(): retrieve column names and types cheaply (no rows)
  • fetch(**params): execute and return a pd.DataFrame
  • describe(): produce a human-readable string for the LLM
  • cache_key: a stable, unique string for Redis keying

Key rule: prefetch_schema must be cheap — a single metadata query, no data rows. fetch is the expensive call, only triggered on demand.

Cache key ownership: The cache_key is owned by DataSource, not by the agent name. Two different agents registering the same source (e.g. same QuerySlugSource slug) will share the same Redis cache entry.

Class DataSource

Abstract base for all data sources.

A DataSource is a reference to data. It knows how to prefetch schema, fetch actual data, describe itself to the LLM, and provide a stable cache key for Redis.

Parameter Type Default Description
routing_meta Dict | None None Optional routing hints dict. Defaults to empty dict.

Attributes:

Attribute Type Description
routing_meta Dict Optional dict of routing hints for CapabilityRegistry. Supported keys: - "description": overrides describe() for embedding. - "not_for": list of query patterns to avoid. Example: {"description": "Q1 sales", "not_for": ["HR"]}
has_builtin_cache bool Whether this source manages its own caching internally. When True, DatasetManager will skip its Redis caching layer and delegate cache management (including force-refresh semantics) entirely to the source. Override to True in sources like QuerySlugSource that rely on QuerySource's own caching infrastructure.
self_governed bool Whether this source enforces its own authorization and returns subject-scoped rows. When True, DatasetManager does not wrap the source in AuthorizingDataSource, always re-fetches, never uses its Redis cache, keeps its DataFrame per calling subject (see current_owner) and never copies it to another manager.
cache_key str Stable, unique string for Redis keying. The key is shared across agents — two agents registering the same logical source (e.g. same query slug) will hit the same Redis entry.

Method DataSource.prefetch_schema

Return column-to-type mapping without fetching any rows.

Subclasses override when cheap schema discovery is available (e.g. INFORMATION_SCHEMA query for TableSource, or a 1-row fetch for QuerySlugSource). The default returns an empty dict, meaning schema is unknown until the first fetch.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Dictionary mapping column names to their type strings. Returns empty dict if schema is unavailable without fetching.

Method DataSource.fetch

Execute and return a DataFrame.

This is the expensive call — only triggered on demand (materialization). Implementations should connect to the data source, execute the query, and return the result as a pandas DataFrame.

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} Source-specific parameters (e.g. SQL template values, query conditions, filter criteria).

Returns: pd.DataFrame — A pandas DataFrame with the fetched data.

Raises:

  • ValueError — If required params are missing or invalid.
  • RuntimeError — If the data source is unreachable or returns no data.

Method DataSource.describe

Return a human-readable description for the LLM guide.

This string is used in list_available() and the DataFrame guide to explain to the LLM what this data source contains and how to use it.

describe() -> str

Returns: str — A short descriptive string (1–2 lines).

Method DataSource.current_owner

Opaque, stable identifier of the subject calling right now, or None.

Only consulted for self_governed sources: DatasetEntry keys the loaded DataFrame by it.

current_owner() -> str | None

Returns: str | None — None by default, and None whenever no subject can be resolved.

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