@rasmusengelbrecht/pi-semantic-query
v0.1.6
Published
Compile and inspect governed semantic metrics from pi coding agent
Maintainers
Readme
pi-semantic-query
Pi extension for working with governed semantic metrics from semantic-query-compiler.
It gives pi tools to discover metrics, inspect definitions, validate a model, and compile metric requests to SQL. It does not execute warehouse queries.
Requirements
- pi coding agent
- Node/npm for installing the pi package
semantic-query-compiler >= 0.1.4installed so thesemanticCLI is onPATH- a semantic model in the project, usually
semantic.yml
Install the Python compiler first:
uv tool install 'semantic-query-compiler>=0.1.4'
semantic --versionInstall in pi
From npm, after publishing:
pi install npm:@rasmusengelbrecht/pi-semantic-queryFor local development:
pi install /absolute/path/to/pi-semantic-queryOr try without installing:
pi -e /absolute/path/to/pi-semantic-queryTools
The package registers a bundled semantic-query skill plus these pi tools:
semantic_metrics— list metrics with discovery metadatasemantic_search_metrics— search metrics by id, name, description, synonyms, and teamssemantic_describe— describe one metric definitionsemantic_validate— validate a semantic modelsemantic_compile— compile a metric request to SQL
The skill teaches pi the default workflow: search before guessing metric IDs, describe ambiguous metrics, validate model changes, prefer period, and never present compiled SQL as executed results.
All tools shell out to the local semantic CLI. If target relation flags fail with unrecognized arguments, upgrade the Python CLI:
uv tool install 'semantic-query-compiler>=0.1.4' --forceBy default tools look for one of:
semantic.ymlsemantic.yamlmodel.ymlmodel.yamlsemantic_layer.ymlsemantic_layer.yaml
Pass model explicitly when your file lives somewhere else.
Example prompt
List available semantic metrics in this repo, find the revenue metric, then compile revenue by country for the last 12 complete months.
The agent should:
- call
semantic_search_metrics - call
semantic_describefor the chosen metric - call
semantic_compilewith an inline request shape andperiod
Example request shape for semantic_compile:
{
"metricId": "revenue",
"period": "last 12 complete months",
"dialect": "bigquery",
"request": {
"timeGrain": "monthly",
"breakdownDimensionIds": ["country"]
}
}For target series, pass targetTable. semantic-query-compiler >= 0.1.4 accepts both core target column conventions (metric_id/target_series/metric_time/target_value and metric/series/time/value) on BigQuery. Use targetProject and targetSchema when the warehouse needs a qualified target relation but you want to keep the table name generic:
{
"metricId": "revenue",
"period": "current year",
"dialect": "bigquery",
"targetProject": "warehouse-project",
"targetSchema": "analytics",
"targetTable": "metric_targets",
"request": {
"timeGrain": "monthly",
"targetSeries": "budget_current"
}
}Safety boundary
This package is compile-only by design. semantic_compile returns SQL; it does not run the SQL. Query execution touches credentials, cost, and data access, so execution should stay in the caller's existing warehouse tooling or a separate explicitly configured integration.
Publishing
npm pack --dry-run
npm publish --access publicThe pi-package keyword makes the package discoverable by pi package indexes.
