/wire:snowflake-semantic-viewsfrom wire
Creates, alters, validates, and debugs Snowflake semantic views for Cortex Analyst. Covers SQL DDL, YAML, FastGen, and VQR validation workflows.
Ships in wire. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Before proceeding, append a one-line entry to .wire/execution_log.md:
| YYYY-MM-DD HH:MMZ | skill | snowflake-semantic-views | Snowflake semantic view work triggered this skill | <by> | <session> | n/a | n/a | n/a |
Snowflake semantic views are the metadata layer that powers Cortex Analyst — Snowflake's natural-language-to-SQL service. A semantic view maps business concepts (entities, facts, dimensions, metrics, relationships) onto physical tables so Cortex can generate accurate SQL from plain English questions.
This skill governs how we create, modify, validate, and audit them. It operates via the Snowflake MCP server (mcp__claude_ai_Snowflake__sql_exec) and the Snowflake CLI (snow) where available.
CREATE SEMANTIC VIEW, CORTEX ANALYST, or SYSTEM$CORTEX_ANALYST_FAST_GENERATION.semantic.yaml or semantic_view.sqlBefore any work:
SELECT CURRENT_ROLE(), CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA();
Confirm role has CREATE SEMANTIC VIEW privilege on the target schema. If not, advise the user on the grant needed:
GRANT CREATE SEMANTIC VIEW ON SCHEMA my_db.my_schema TO ROLE analyst_role;
Check if FastGen is available (Snowflake Enterprise / Business Critical, 2024+):
SELECT SYSTEM$CORTEX_ANALYST_FAST_GENERATION IS NOT NULL;
If this returns an error rather than TRUE/FALSE, FastGen is not available — fall back to SQL DDL or YAML workflow.
| Mode | When to use |
|---|---|
| FastGen (preferred) | New view from existing tables; FastGen available; tables have comments and PKs |
| SQL DDL | Full control needed; FastGen unavailable; complex relationship graph |
| YAML | Iterative editing; version-controlled definitions; SYSTEM$CREATE_SEMANTIC_VIEW_FROM_YAML available |
| Existing view retrieval | Editing or auditing an existing semantic view |
Always run schema discovery before authoring DDL or YAML.
Get table structure:
DESCRIBE TABLE my_db.my_schema.orders;
Get existing column comments:
SELECT column_name, data_type, comment
FROM information_schema.columns
WHERE UPPER(table_schema) = UPPER('MY_SCHEMA')
AND UPPER(table_name) = UPPER('ORDERS')
ORDER BY ordinal_position;
Get primary/unique keys (required for RELATIONSHIP targets):
SHOW PRIMARY KEYS IN TABLE my_db.my_schema.orders;
SHOW UNIQUE KEYS IN TABLE my_db.my_schema.orders;
Sample data to understand values:
SELECT * FROM my_db.my_schema.orders LIMIT 20;
If editing an existing semantic view, retrieve the current definition:
SELECT GET_DDL('SEMANTIC VIEW', 'my_db.my_schema.orders_sv');
Follow this clause order exactly — Snowflake parses the DDL sequentially and references in later clauses depend on earlier declarations:
CREATE OR REPLACE SEMANTIC VIEW my_db.my_schema.orders_sv
TABLES (
orders PRIMARY KEY (order_id)
COMMENT 'Transactional order records',
customers PRIMARY KEY (customer_id)
COMMENT 'Customer master'
)
RELATIONSHIPS (
orders FOREIGN KEY (customer_id) REFERENCES customers
)
FACTS (
orders (
order_id COMMENT 'Unique order identifier',
order_date COMMENT 'Date the order was placed',
order_total COMMENT 'Total order value in USD'
)
)
DIMENSIONS (
customers (
customer_id COMMENT 'Unique customer identifier',
customer_name COMMENT 'Full name of the customer',
country COMMENT 'Customer billing country'
)
)
METRICS (
total_revenue AS SUM(orders.order_total)
COMMENT 'Sum of all order totals',
order_count AS COUNT(DISTINCT orders.order_id)
COMMENT 'Number of distinct orders',
avg_order_value AS AVG(orders.order_total)
COMMENT 'Average order total'
)
COMMENT = 'Semantic model for order analytics. Supports Cortex Analyst queries on revenue, customer behaviour, and order volume.'
AI_SQL_GENERATION ENABLED
AI_QUESTION_CATEGORIZATION ENABLED;
Rules:
facts not measures — measures is deprecatedPRIMARY KEY or have one defined on the physical tableRELATIONSHIP targets must have a unique or primary key on the referenced columnAI_SQL_GENERATION ENABLED unlocks Cortex Analyst; omitting it makes the view non-queryable by CortexAI_QUESTION_CATEGORIZATION ENABLED groups suggested questions by topic — add unless told otherwiseValidate with a temp name before final deployment:
CREATE OR REPLACE SEMANTIC VIEW my_db.my_schema.orders_sv__tmp_validate
-- same DDL as above
;
-- Smoke test
SELECT * FROM my_db.my_schema.orders_sv__tmp_validate LIMIT 1;
-- Clean up
DROP SEMANTIC VIEW my_db.my_schema.orders_sv__tmp_validate;
Only deploy the real name after validation passes.
When working iteratively or version-controlling the definition:
orders_sv.semantic.yamlTRUE):SELECT SYSTEM$CREATE_SEMANTIC_VIEW_FROM_YAML(
'my_db.my_schema.orders_sv',
$$ <yaml content here> $$,
TRUE -- verify-only, no deployment
);
If verify-only returns no errors:
SELECT SYSTEM$CREATE_SEMANTIC_VIEW_FROM_YAML(
'my_db.my_schema.orders_sv',
$$ <yaml content here> $$,
FALSE -- deploy
);
YAML format mirrors the DDL structure — tables, relationships, facts, dimensions, metrics, comments — as a structured YAML document. Get the schema from DESCRIBE SEMANTIC VIEW on an existing view or Snowflake documentation.
When FastGen is available:
SELECT SYSTEM$CORTEX_ANALYST_FAST_GENERATION(
'my_db.my_schema', -- target schema
ARRAY_CONSTRUCT('orders', 'customers', 'products') -- tables to include
);
FastGen returns a draft YAML. Review it before deploying:
Then deploy via the YAML workflow above.
Verified queries are example NL-question → SQL pairs that Cortex uses as few-shot examples. They dramatically improve accuracy on common questions.
Rules:
orders_sv.total_revenue, not SUM(orders.order_total)Add via DDL:
ALTER SEMANTIC VIEW my_db.my_schema.orders_sv
ADD AI_VERIFIED_QUERIES (
(
QUESTION = 'What was total revenue last month?',
SQL = 'SELECT orders_sv.total_revenue FROM orders_sv WHERE DATE_TRUNC(''month'', orders_sv.order_date) = DATE_TRUNC(''month'', DATEADD(month, -1, CURRENT_DATE()))'
),
(
QUESTION = 'Who are the top 10 customers by revenue?',
SQL = 'SELECT orders_sv.customer_name, orders_sv.total_revenue FROM orders_sv ORDER BY orders_sv.total_revenue DESC LIMIT 10'
)
);
Never add VQRs that return different results across runs (non-deterministic queries with relative date logic can drift — use fixed date ranges for testing, then adjust for production use).
When asked to audit all semantic views in an account or schema:
-- List all semantic views
SHOW SEMANTIC VIEWS IN DATABASE my_db;
-- Get DDL for each
SELECT GET_DDL('SEMANTIC VIEW', 'my_db.my_schema.orders_sv');
For each semantic view, check:
| Check | Pass Condition |
|---|---|
| All tables have PRIMARY KEY declared | No table block missing PRIMARY KEY |
| All RELATIONSHIP targets have unique key | Foreign key references a PK or UNIQUE key column |
| All facts/dimensions/metrics have COMMENTs | No empty COMMENT strings |
AI_SQL_GENERATION is enabled | Present in DDL |
| At least 3 verified queries present | Count VQR entries in DDL |
| View compiles without error | GET_DDL returns without exception |
| Cortex can answer a test question | Run CORTEX.ANALYST with a test prompt |
Produce an audit table:
## Semantic View Audit — my_db
Date: {TODAY}
| View | Tables | Relationships | Metrics | VQRs | Missing Comments | AI Enabled | Status |
|------|--------|---------------|---------|------|-----------------|------------|--------|
| orders_sv | 2 | 1 | 3 | 5 | 0 | Yes | PASS |
| products_sv | 3 | 0 | 2 | 0 | 4 | Yes | WARN: no relationships, no VQRs, 4 missing comments |
When Cortex Analyst generates wrong SQL:
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong join path | Missing or incorrect RELATIONSHIP | Add/correct the foreign key relationship |
| Metric calculation wrong | Metric formula too broad (missing filter) | Refine metric definition or add a filtered variant |
| Missing column | Column not declared in FACTS or DIMENSIONS | Add the column with a comment |
| Ambiguous column name | Same name appears in multiple tables | Prefix in the fact/dimension block: orders.status COMMENT '...' |
| Date filter wrong | No temporal scope declared | Add a temporal_scope annotation or VQR with correct date logic |
| Wrong aggregation | Metric defined as SUM but user wants COUNT | Add a second metric, or clarify with a verified query |
Always ask before:
ACCOUNT_USAGE.QUERY_HISTORY — requires approval)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub rittmananalytics/wire-plugin --plugin wire74 skills in this plugin
/add-analytics-instrumentationEnd-to-end analytics instrumentation workflow for a PR, branch, file, directory, or feature. Reads the code, discovers what events should be tracked, and produces a concrete instrumentation plan — all in one shot. Use this skill whenever a user wants to add analytics to a PR, asks "instrument this PR", "add tracking to this branch", "what analytics does this file need", "instrument the checkout flow", "run the full instrumentation workflow", or any request that implies going from code changes to a tracking plan. Also trigger when the user gives you a PR link, branch name, file path, or feature description and mentions analytics, events, or instrumentation. This is the main entry point for the analytics workflow — prefer it over calling the individual steps (diff-intake, discover-event-surfaces, instrument-events) separately.
/agents-schemaPublish and read warehouse metadata through dbt Labs' Agents Schema (the AGENTS schema inside Snowflake, Databricks or BigQuery, written by the agents-schema CLI from a dbt manifest, LookML, Omni, OSI, Sigma and markdown skills). Activates when the user mentions Agents Schema, agents_schema, AGENTS.ROOT, the agents-schema CLI or its GitHub workflows, warehouse-delivered skills, or asks how an AI agent should find governed context for a warehouse. Used by /wire:agents_schema-generate, -validate and -review, and for ad-hoc work against an AGENTS schema.