Skip to content

API Reference parrot_tools.querysource.toolkit

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

parrot_tools.querysource.toolkit

View source

QuerysourceToolkit — tenant-scoped QuerySource tools for agents (spec FEAT-558 §3 M5/M6).

Generated tool names (tool_prefix 'qs'): qs_get_dialect_reference, qs_list_slugs, qs_describe_slug, qs_execute_slug, qs_build_linked_surface, qs_build_linked_dashboard, qs_list_components, qs_validate_pipeline, qs_run_multiquery and — only when allow_write=True — qs_save_multiquery.

Alias ComponentDoc

Re-exported from parrot_tools.querysource.models.ComponentDoc.

Alias DIALECT_REFERENCE

Re-exported from parrot_tools.querysource.dialect.DIALECT_REFERENCE.

Alias DashboardSource

Re-exported from parrot_tools.querysource.models.DashboardSource.

Alias DashboardWidget

Re-exported from parrot_tools.querysource.models.DashboardWidget.

Alias DialectReference

Re-exported from parrot_tools.querysource.models.DialectReference.

Alias ExecutionResult

Re-exported from parrot_tools.querysource.models.ExecutionResult.

Alias FilterValue

Re-exported from parrot_tools.querysource.models.FilterValue.

Alias InvalidConditionsError

Re-exported from parrot_tools.querysource.errors.InvalidConditionsError.

Alias MultiQueryResult

Re-exported from parrot_tools.querysource.models.MultiQueryResult.

Alias NormalizedPipeline

Re-exported from parrot_tools.querysource.catalog.NormalizedPipeline.

Alias PipelineIssue

Re-exported from parrot_tools.querysource.models.PipelineIssue.

Alias PipelineValidation

Re-exported from parrot_tools.querysource.models.PipelineValidation.

Alias PlaceholderInfo

Re-exported from parrot_tools.querysource.models.PlaceholderInfo.

Class QuerysourceToolkit

Explain, list, describe and execute QuerySource query-slugs and MultiQuery pipelines, scoped to tenants.

Parameter Type Default Description
programs list[str] | None None
allow_write bool False
allow_raw_sql bool False
allow_external_sources bool True
include_sql bool True
max_rows int 200
forced_conditions dict[str, Any] | None None
dsn str | None None
multiquery_timeout float 600.0
**kwargs Any {}

Attributes:

Attribute Type Description
tool_prefix str | None
exclude_tools tuple[str, ...]
confirming_tools frozenset[str]
auto_open bool
restricted bool

Method QuerysourceToolkit.config_options

Dynamic choices for Agent Studio (FEAT-593): catalog program slugs for programs.

config_options(param: str) -> list[ConfigOption]

Parameter Type Default Description
param str

Returns: list[ConfigOption]

Method QuerysourceToolkit.get_dialect_reference

Return the QuerySource conditions dialect: which keys are options, which become placeholders, which become WHERE filters, the WHERE value grammar with examples, and the '@variables' this deployment accepts as values (e.g. '@today'). Call this before building conditions.

get_dialect_reference() -> DialectReference

Returns: DialectReference

Method QuerysourceToolkit.list_slugs

List query-slugs visible to this toolkit (allowlist-filtered). search matches slug or description. tenant selects a QuerySource tenant store schema; omit it for public/legacy slugs. Routing, not security.

list_slugs(search: str | None = None, program: str | None = None, limit: int = 50, tenant: str | None = None) -> list[SlugSummary]

Parameter Type Default Description
search str | None None
program str | None None
limit int 50
tenant str | None None

Returns: list[SlugSummary]

Method QuerysourceToolkit.describe_slug

Explain a slug: placeholders and types, stored defaults, filtering/fields/ordering/grouping, provider, program, and — when the toolkit is configured with include_sql — the SQL or pipeline JSON. dry_run=True also returns the rendered query via QS.dry_run() (this performs provider setup, not a pure catalog read). tenant selects a QuerySource tenant store schema; omit it for public/legacy slugs. Routing, not security. Each placeholder reports required and accepts_keywords.

describe_slug(slug: str, dry_run: bool = False, tenant: str | None = None) -> SlugDetail

Parameter Type Default Description
slug str
dry_run bool False
tenant str | None None

Returns: SlugDetail

Method QuerysourceToolkit.execute_slug

Run a query-slug. placeholders fill the slug's declared conditions (see qs_describe_slug); filter adds WHERE clauses in the dialect grammar (see qs_get_dialect_reference); fields, ordering, grouping override the stored projection; limit is capped at the toolkit's max_rows; refresh bypasses the QuerySource cache. tenant selects a QuerySource tenant store schema; omit it for public/legacy slugs. Routing, not security. Returns bounded rows plus returned_rows/total_rows/truncated.

execute_slug(slug: str, placeholders: dict[str, Any] | None = None, filter: dict[str, FilterValue] | None = None, fields: list[str] | None = None, ordering: list[str] | None = None, grouping: list[str] | None = None, limit: int | None = None, offset: int | None = None, refresh: bool = False, tenant: str | None = None) -> ExecutionResult

Parameter Type Default Description
slug str
placeholders dict[str, Any] | None None
filter dict[str, FilterValue] | None None
fields list[str] | None None
ordering list[str] | None None
grouping list[str] | None None
limit int | None None
offset int | None None
refresh bool False
tenant str | None None

Returns: ExecutionResult

Method QuerysourceToolkit.build_linked_surface

Emit a linked A2UI surface for a query slug.

component is a Chart, DataTable, or KPICard without its data binding; the toolkit adds the binding. request accepts placeholders, filter, fields, ordering, grouping, limit, and offset in the qs_execute_slug grammar. Relative dates use UDF keywords (TODAY, YESTERDAY, FDOM, LDOM, CURRENT_YEAR, CURRENT_MONTH, LAST_YEAR); @variables are rejected. By default (snapshot=False) the surface is definition-only: the slug is only probed with querylimit=1 to validate columns and dtypes, the envelope carries no rows, and the renderer fetches them on mount. Pass snapshot=True only when viewers cannot fetch for themselves (share links, offline export): it runs the full query and embeds up to 500 current rows. refresh accepts policy (on_mount, manual, interval) and interval_seconds; transform accepts the linked transform DSL. A source may instead declare {"python": {"transformer": "<registered name>", "params": {...}, "input_alias": "source", "output": null}}, a server-side registered transformer; it is terminal (no derived views/joins may consume that source) and the renderer fetches it through the server.

build_linked_surface(slug: str, component: dict[str, Any], request: dict[str, Any] | None = None, tenant: str | None = None, snapshot: bool = False, surface_id: str | None = None, target_key: str | None = None, refresh: dict[str, Any] | None = None, transform: dict[str, Any] | None = None) -> dict[str, Any]

Parameter Type Default Description
slug str
component dict[str, Any]
request dict[str, Any] | None None
tenant str | None None
snapshot bool False
surface_id str | None None
target_key str | None None
refresh dict[str, Any] | None None
transform dict[str, Any] | None None

Returns: dict[str, Any]

Method QuerysourceToolkit.build_linked_dashboard

Emit ONE linked A2UI dashboard surface whose data sources are owned by the dashboard.

sources maps a source key to {slug, request?, tenant?, refresh?, transform?} (a source transform may be the DSL or a server-side {"python": {"transformer": "<registered name>", ...}}, which is terminal): each is fetched ONCE when the dashboard loads and shared by every widget that reads it — e.g. one query computing six KPIs feeds six KPICards. Each widget {key, component, section?} declares exactly one data origin: source (a key of sources; add transform DSL ops to derive a view such as a category aggregation of the rows another widget shows in full), slug (its own query-slug source with request?/tenant?/refresh?, refreshed independently), or data (inline rows, ≤500). Components are Chart, DataTable or KPICard without bindings; a KPICard names its column in value. KPIs, charts and tables are laid out in rows. By default (snapshot=False) the dashboard is definition-only: every slug is only probed with querylimit=1 to validate columns and dtypes, the envelope carries no rows, and the renderer fetches them on mount. Pass snapshot=True only when viewers cannot fetch for themselves (share links, offline export): it runs every query in full and embeds up to 500 rows per source. Raises InvalidConditionsError on bad/duplicate keys, unknown sources or grammar; QuerysourceToolkitError when a source fails to execute.

build_linked_dashboard(widgets: list[dict[str, Any]], surface_id: str | None = None, title: str | None = None, snapshot: bool = False, sources: dict[str, dict[str, Any]] | None = None) -> dict[str, Any]

Parameter Type Default Description
widgets list[dict[str, Any]]
surface_id str | None None
title str | None None
snapshot bool False
sources dict[str, dict[str, Any]] | None None

Returns: dict[str, Any]

Method QuerysourceToolkit.list_components

List MultiQuery pipeline components (Operators, Transformations, Sources, Destinations) with their JSON schema and a usage example — the same catalog as GET /api/v3/qs/components. Optional category filter.

list_components(category: str | None = None) -> list[ComponentDoc]

Parameter Type Default Description
category str | None None

Returns: list[ComponentDoc]

Method QuerysourceToolkit.validate_pipeline

Validate a MultiQuery pipeline without running it: structural rules (known step names, ≥1 source, Join/Merge arity) plus this toolkit's policy — every queries[*] slug must be one this instance may execute; raw SQL nodes, external sources and destination (write) steps are reported when the configuration forbids them.

validate_pipeline(pipeline: dict[str, Any]) -> PipelineValidation

Parameter Type Default Description
pipeline dict[str, Any]

Returns: PipelineValidation

Method QuerysourceToolkit.run_multiquery

Run a MultiQuery pipeline inline (pipeline, the JSON with queries/Join/Concat/…/Output) or a saved multi-query slug (slug). Every referenced slug must be executable by this toolkit; raw SQL nodes, external sources and destination steps follow the instance configuration (see qs_validate_pipeline). tenant selects a QuerySource tenant store schema; omit it for public/legacy slugs. Routing, not security. Results are bounded per frame.

run_multiquery(pipeline: dict[str, Any] | None = None, slug: str | None = None, conditions: dict[str, Any] | None = None, tenant: str | None = None) -> MultiQueryResult

Parameter Type Default Description
pipeline dict[str, Any] | None None
slug str | None None
conditions dict[str, Any] | None None
tenant str | None None

Returns: MultiQueryResult

Method QuerysourceToolkit.save_multiquery

Persist a validated MultiQuery pipeline as a query-slug owned by program (forced to the single allowed program when this toolkit is tenant-restricted). Requires operator opt-in (allow_write) and user confirmation. Refuses to overwrite a slug owned by another program; set overwrite=True to update your own.

save_multiquery(slug: str, pipeline: dict[str, Any], description: str, program: str | None = None, overwrite: bool = False) -> SavedSlug

Parameter Type Default Description
slug str
pipeline dict[str, Any]
description str
program str | None None
overwrite bool False

Returns: SavedSlug

Alias QuerysourceToolkitConfig

Re-exported from parrot_tools.querysource.config.QuerysourceToolkitConfig.

Alias QuerysourceToolkitError

Re-exported from parrot_tools.querysource.errors.QuerysourceToolkitError.

Alias RawSqlForbiddenError

Re-exported from parrot_tools.querysource.errors.RawSqlForbiddenError.

Alias SavedSlug

Re-exported from parrot_tools.querysource.models.SavedSlug.

Alias SlugCatalog

Re-exported from parrot_tools.querysource.catalog.SlugCatalog.

Alias SlugDetail

Re-exported from parrot_tools.querysource.models.SlugDetail.

Alias SlugNotFoundError

Re-exported from parrot_tools.querysource.errors.SlugNotFoundError.

Alias SlugRecord

Re-exported from parrot_tools.querysource.catalog.SlugRecord.

Alias SlugSummary

Re-exported from parrot_tools.querysource.models.SlugSummary.

Alias TenantDeniedError

Re-exported from parrot_tools.querysource.errors.TenantDeniedError.

Alias TenantGuard

Re-exported from parrot_tools.querysource.catalog.TenantGuard.

Alias WriteDisabledError

Re-exported from parrot_tools.querysource.errors.WriteDisabledError.

Alias build_conditions

Re-exported from parrot_tools.querysource.dialect.build_conditions.

Alias check_version_compatibility

Re-exported from parrot_tools.querysource.dialect.check_version_compatibility.

Alias frame_to_result

Re-exported from parrot_tools.querysource.results.frame_to_result.

Alias load_variables

Re-exported from parrot_tools.querysource.dialect.load_variables.

Alias multi_to_result

Re-exported from parrot_tools.querysource.results.multi_to_result.

Alias normalize_pipeline

Re-exported from parrot_tools.querysource.catalog.normalize_pipeline.

Alias reject_variable_values

Re-exported from parrot_tools.querysource.dialect.reject_variable_values.

Alias validate_filter

Re-exported from parrot_tools.querysource.dialect.validate_filter.

Alias validate_placeholders

Re-exported from parrot_tools.querysource.dialect.validate_placeholders.

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