Skip to content

Add ca_extensions macro for Cortex Analyst verified queries - #30

Open
tylerjrichards wants to merge 1 commit into
Snowflake-Labs:mainfrom
tylerjrichards:feat/verified-queries-macro
Open

Add ca_extensions macro for Cortex Analyst verified queries#30
tylerjrichards wants to merge 1 commit into
Snowflake-Labs:mainfrom
tylerjrichards:feat/verified-queries-macro

Conversation

@tylerjrichards

@tylerjrichards tylerjrichards commented Jul 17, 2026

Copy link
Copy Markdown

Summary

It is annoying that our dbt setup doesn't include the ability to use custom instructions and VQRs, this is how the product data team handles this in our materialization. Thought I would go and fix!

Now to the Coco summary:

  • Adds a ca_extensions Jinja macro (macros/ca_extensions.sql) that generates the WITH EXTENSION (CA=$$...$$) block for Cortex Analyst enrichments
  • Supports verified_queries, custom_instructions, relationships, and per-table tables metadata — only emits keys that have values
  • Adds an integration test model (integration_tests/models/semantic_view_with_verified_queries.sql) that exercises the macro end-to-end
  • Documents the macro in README under a new 'Cortex Analyst enrichments' section with a parameter table, field reference, and complete example

Motivation

The existing semantic_view_with_ca_extension.sql integration test shows that users currently have to hand-write raw JSON strings in the with extension clause. That is error-prone and hard to maintain. This macro lets users define verified queries as structured Jinja dicts and relies on | tojson for correct serialisation.

Adds a `ca_extensions` Jinja macro that generates the
`WITH EXTENSION (CA=$$...$$)` block for Cortex Analyst enrichments
(verified queries, custom instructions, relationships, per-table metadata).

Previously users had to hand-write JSON inline, as seen in the existing
`semantic_view_with_ca_extension.sql` integration test. The new macro
accepts structured Python/Jinja dicts, serialises them with `| tojson`,
and only includes keys that have values — keeping the DDL clean.

Changes:
- macros/ca_extensions.sql: new macro with full parameter docs
- integration_tests/models/semantic_view_with_verified_queries.sql: test
  using the macro with a verified query, custom_instructions
- README.md: new "Cortex Analyst enrichments" section with parameter
  table, field reference, and a complete example

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants