Skip to content

API Reference parrot.tools.dataset_manager.sources.resolver

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

parrot.tools.dataset_manager.sources.resolver

View source

Physical-Resource Resolver for FEAT-228 Data-Plane Authorization.

Pure function module that maps any :class:~parrot.tools.dataset_manager.sources.base.DataSource to the set of physical resources (driver + tables / source identifiers) it will actually touch when executed.

This is the anti-alias-spoofing boundary: authorization decisions are made on what the source physically accesses, not on the LLM-chosen dataset name.

Architecture (Spec §2, Module 1):

  • SQL sources: sqlglot parses the query and extracts physical table references, excluding CTE aliases. A read-only gate rejects DML/DDL.
  • TableSource: trivially extracts driver:table from instance attributes.
  • QuerySlugSource: returns empty resources (slug-level grants handled separately).
  • InMemorySource: returns empty resources (no driver round-trip).
  • Opaque sources (Mongo, Iceberg, Delta, Airtable, Smartsheet): delegates to :mod:parrot.tools.dataset_manager.sources.opaque.

Usage::

from parrot.tools.dataset_manager.sources.resolver import (
    resolve_physical_resources, physical_tables,
    PhysicalResources, ReadOnlyViolation,
)

resources = resolve_physical_resources(my_sql_source)
# resources.driver = "bigquery"
# resources.tables = {"bigquery:schema.table"}

Class PhysicalResources

Resolved physical resources for a DataSource.

Fields:

Field Type Default Description
driver Optional[str] None Canonical driver name (e.g. "bigquery", "pg").
tables set[str] Set of table resource strings in "driver:schema.table" form, used as resource IDs in the PBAC engine (table:<driver>:<schema>.<table>).
source_type Optional[str] None Non-SQL source type identifier (e.g. "mongo").
source_id Optional[str] None Non-SQL source identifier (e.g. "finance_db.transactions").

Class ReadOnlyViolation

Raised when a SQL statement is not read-only (DML/DDL detected).

The read-only gate is enforced before any network round-trip so that mutation attempts are caught at parse time.

Function physical_tables

Extract physical table references from a SQL query using sqlglot.

Parses the SQL with dialect and walks the AST looking for exp.Table nodes, excluding any names that are CTE aliases (because those are virtual, not physical tables).

The read-only gate checks the top-level node type. Any statement whose root is not SELECT/UNION/SUBQUERY/WITH raises :class:ReadOnlyViolation.

Examples::

>>> physical_tables("SELECT * FROM sales.orders", "postgres")
{'sales.orders'}
>>> physical_tables("DROP TABLE x", "postgres")  # raises ReadOnlyViolation

physical_tables(sql: str, dialect: str) -> set[str]

Parameter Type Default Description
sql str SQL query string to analyse.
dialect str sqlglot dialect name (e.g. "postgres", "bigquery").

Returns: set[str] — Set of physical table names in schema.table or table form.

Raises:

  • ReadOnlyViolation — If the statement is not a read-only query.
  • sqlglot.errors.ParseError — If the SQL cannot be parsed.

Function resolve_physical_resources

Resolve a DataSource to the set of physical resources it will touch.

Dispatches on the source type:

  • :class:~parrot.tools.dataset_manager.sources.sql.SQLQuerySource: sqlglot parse + table extraction.
  • :class:~parrot.tools.dataset_manager.sources.table.TableSource: trivial single-table extraction.
  • :class:~parrot.tools.dataset_manager.sources.query_slug.QuerySlugSource: returns empty (slug grants handled separately).
  • :class:~parrot.tools.dataset_manager.sources.memory.InMemorySource: returns empty (no driver round-trip).
  • All other sources: delegates to :mod:.opaque resolver.

resolve_physical_resources(source: 'DataSource') -> PhysicalResources

Parameter Type Default Description
source 'DataSource' Any :class:~parrot.tools.dataset_manager.sources.base.DataSource subclass.

Returns: PhysicalResources — class:PhysicalResources describing what the source accesses.

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