|
| 1 | +author: Srinivasan Kuppusamy |
| 2 | +id: accelerate-data-product-delivery |
| 3 | +language: en |
| 4 | +summary: Learn how to accelerate data product delivery from requirements to production in one sprint using Snowflake Cortex Code. Automate design, code generation, governance, and monitoring using an AI agent and a machine-readable data contract. Uses an FSI example but applicable to any industry. |
| 5 | +categories: snowflake-site:taxonomy/solution-center/certification/quickstart,snowflake-site:taxonomy/product/ai,snowflake-site:taxonomy/product/data-engineering,snowflake-site:taxonomy/snowflake-feature/compliance-security-discovery-governance,snowflake-site:taxonomy/snowflake-feature/cortex-llm-functions,snowflake-site:taxonomy/industry/financial-services |
| 6 | +environments: web |
| 7 | +status: Published |
| 8 | +feedback link: https://github.com/Snowflake-Labs/sfquickstarts/issues |
| 9 | +fork repo link: https://github.com/srini86/data-products-lifecycle-fsi-example |
| 10 | + |
| 11 | +# Accelerate Data Product Delivery with Snowflake Cortex Code |
| 12 | +<!-- ------------------------ --> |
| 13 | +## Overview |
| 14 | + |
| 15 | +Duration: 5 minutes |
| 16 | + |
| 17 | +This guide shows how to deliver a governed data product in **a single sprint** using [Cortex Code (CoCo)](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-code) and a machine-readable **data contract** as the single source of truth. One document captures the requirements; an agent reads it and generates, deploys, and monitors every artifact automatically. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +The example uses a **Retail Customer Churn Risk** data product in a retail banking context, but the approach works for any data product in any industry. |
| 22 | + |
| 23 | +> **Note:** The Discover phase is pre-done. Open `01_discover/data_product_canvas.png` to see the agreed requirements — this canvas is the only input to all phases that follow. The sprint goal is to deliver `RETAIL_BANKING_DB.DATA_PRODUCTS.RETAIL_CUSTOMER_CHURN_RISK` — governed, tested, and monitored — by end of sprint. |
| 24 | +
|
| 25 | +### What You'll Learn |
| 26 | + |
| 27 | +- How a machine-readable data contract (ODCS v2.2) drives all downstream automation — one document replaces days of manual artifact authoring |
| 28 | +- How a Cortex Code agent generates a dbt project, masking policies, and DMF quality checks from the contract in minutes |
| 29 | +- How to deploy, monitor, and evolve a governed data product on Snowflake |
| 30 | + |
| 31 | +### What You'll Need |
| 32 | + |
| 33 | +- A Snowflake account with `ACCOUNTADMIN` role |
| 34 | +- [Cortex Code (CoCo) CLI](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-code) installed |
| 35 | +- [Snow CLI](https://docs.snowflake.com/en/developer-guide/snowflake-cli/index) installed |
| 36 | +- Git |
| 37 | + |
| 38 | +### What You'll Build |
| 39 | + |
| 40 | +In one sprint you will produce a complete, production-ready data product. Source tables are pre-loaded — everything below is generated and deployed by the Cortex Code agent: |
| 41 | + |
| 42 | +- A dbt model transforming five source tables into a governed output table |
| 43 | +- Masking policies protecting PII columns (email, phone, date of birth) |
| 44 | +- Data Metric Functions enforcing null, range, and freshness quality expectations |
| 45 | +- Automated monitoring for SLA freshness, quality gate status, and usage by role |
| 46 | + |
| 47 | +<!-- ------------------------ --> |
| 48 | +## Environment Setup |
| 49 | + |
| 50 | +Duration: 10 minutes |
| 51 | + |
| 52 | +### Step 1: Clone the Repository |
| 53 | + |
| 54 | +Clone `https://github.com/srini86/data-products-lifecycle-fsi-example` and `cd` into the repo root. |
| 55 | + |
| 56 | +### Step 2: Run Setup SQL in Snowsight |
| 57 | + |
| 58 | +Open `00_setup/setup.sql` in Snowsight and run each step in order: |
| 59 | + |
| 60 | +| Step | What it does | |
| 61 | +|------|-------------| |
| 62 | +| Step 1 | Creates `RETAIL_BANKING_DB` with four schemas (`RAW`, `DATA_PRODUCTS`, `GOVERNANCE`, `MONITORING`) and an XSmall warehouse | |
| 63 | +| Step 2 | Creates two Snowflake stages in `GOVERNANCE`: `data_contracts` and `streamlit_apps` | |
| 64 | +| Step 3 | Creates five source tables in the `RAW` schema | |
| 65 | +| Step 4 | Loads synthetic FSI sample data into the source tables | |
| 66 | +| Step 5 *(optional)* | Deploys a Streamlit code generator app — skip if following the Cortex Code path | |
| 67 | +| Step 6 | Verifies all five source tables exist with expected row counts | |
| 68 | + |
| 69 | +Source tables loaded by Steps 3–4: |
| 70 | + |
| 71 | +| Table | Description | Rows | |
| 72 | +|-------|-------------|------| |
| 73 | +| `CUSTOMERS` | Demographics, segment, KYC status | ~1,000 | |
| 74 | +| `ACCOUNTS` | Accounts by type, balance, status | ~2,500 | |
| 75 | +| `TRANSACTIONS` | Six months of transaction history | ~25,000 | |
| 76 | +| `DIGITAL_ENGAGEMENT` | App logins, feature usage, NPS | ~1,000 | |
| 77 | +| `COMPLAINTS` | Complaint records and resolution times | ~200 | |
| 78 | + |
| 79 | +Confirm Step 6 shows all five tables before continuing. |
| 80 | + |
| 81 | +<!-- ------------------------ --> |
| 82 | +## Start Cortex Code |
| 83 | + |
| 84 | +Duration: 2 |
| 85 | + |
| 86 | +From the repo root, run `cortex` to start a session, then invoke the lifecycle accelerator with `$dplc-accelerator` (or type `start lifecycle`). The skill detects your current phase, displays a progress tracker, and presents each prompt one step at a time. |
| 87 | + |
| 88 | +**Keep this session open for all phases — Design through Refine.** You will return to it at the start of each phase. |
| 89 | + |
| 90 | +<!-- ------------------------ --> |
| 91 | +## Design: Create the Data Contract |
| 92 | + |
| 93 | +Duration: 10 minutes |
| 94 | + |
| 95 | +A data contract (ODCS v2.2 YAML) is the sprint's single source of truth — every artifact in the Deliver phase is generated from it. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +### Prompt 1: Review the Example Contract |
| 100 | + |
| 101 | +Open `02_design/_example/churn_risk_data_contract.yaml`. The contract has three key sections: |
| 102 | + |
| 103 | +**Schema** — every output column with type, description, derivation logic, and a `pii` flag. Columns marked `pii: true` (email, phone, date of birth) automatically trigger masking policy generation in the Deliver phase. |
| 104 | + |
| 105 | +**Quality rules** — null checks on required columns, a value range rule (churn score must be 0–100), and a freshness rule (max 24-hour age). These drive the DMF setup generated in Deliver. |
| 106 | + |
| 107 | +**SLAs and governance** — daily refresh schedule, 99.5% availability target, data steward contact, retention period, and regulatory tags (GDPR, PSD2). These drive the monitoring alerts and access control setup. |
| 108 | + |
| 109 | +### Prompt 2: Generate Your Own Contract *(Optional)* |
| 110 | + |
| 111 | +Use Cortex Code to generate a contract from your own canvas: |
| 112 | + |
| 113 | +"Generate an ODCS v2.2 data contract for `<your data product>`. Use `02_design/_example/churn_risk_data_contract.yaml` as a reference." |
| 114 | + |
| 115 | +<!-- ------------------------ --> |
| 116 | +## Deliver: Cortex Code Agent |
| 117 | + |
| 118 | +Duration: 25 minutes |
| 119 | + |
| 120 | +This phase uses the `dplc-accelerator` skill — an interactive orchestrator that detects your current phase, displays a progress tracker, and presents each prompt one step at a time. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +### Prompt 1: Generate the dbt Project |
| 125 | + |
| 126 | +"Read the data contract at `02_design/_example/churn_risk_data_contract.yaml` and generate a complete dbt project — model SQL, schema.yml, and tests." |
| 127 | + |
| 128 | +Output: `03_deliver/dbt_project/models/` — model SQL joining all five source tables, schema.yml with not_null/unique/accepted_values tests, and singular tests for range and referential integrity rules. |
| 129 | + |
| 130 | +> **Review checkpoint:** Verify the join logic matches the source tables in the contract. Confirm the churn score derivation aligns with the contract's `derivation` field. |
| 131 | +
|
| 132 | +### Prompt 2: Generate Governance Artifacts |
| 133 | + |
| 134 | +"Generate masking policies and DMF setup SQL based on the governance rules in the data contract." |
| 135 | + |
| 136 | +Output: `masking_policies.sql` — one conditional masking policy per `pii: true` column, granting unmasked access to privileged roles only. `dmf_setup.sql` — attaches Snowflake Data Metric Functions for each quality rule, scheduled to match the contract's refresh schedule. |
| 137 | + |
| 138 | +> **Review checkpoint:** Every `pii: true` column has a masking policy. The DMF schedule matches the contract's `refresh_schedule`. |
| 139 | +
|
| 140 | +### Prompt 3: Generate Monitoring SQL |
| 141 | + |
| 142 | +"Generate monitoring and observability SQL — freshness SLAs, quality checks, usage tracking, and alerts." |
| 143 | + |
| 144 | +Output: `04_operate/_example/monitoring_observability.sql` — freshness check, DMF quality dashboard (PASS/FAIL per rule), usage tracking by role/user, and a Snowflake Alert that fires on SLA or quality breach. |
| 145 | + |
| 146 | +> **Review checkpoint:** Confirm the freshness threshold in the generated SQL matches `sla.max_acceptable_lag_hours` (24 hours) from the contract. |
| 147 | +
|
| 148 | +### Prompt 4: Deploy via Snow CLI |
| 149 | + |
| 150 | +"Deploy the dbt project to Snowflake using `snow dbt deploy` and run it." |
| 151 | + |
| 152 | +The agent runs `snow dbt deploy` targeting `RETAIL_BANKING_DB.DATA_PRODUCTS`, then `snow dbt run` to materialise the output table. It then applies masking policies and DMF attachments from Prompts 1 and 2. |
| 153 | + |
| 154 | +> **Review checkpoint:** Confirm `RETAIL_BANKING_DB.DATA_PRODUCTS.RETAIL_CUSTOMER_CHURN_RISK` exists with ~1,000 rows in Snowsight. |
| 155 | +
|
| 156 | +### Prompt 5: Validate the Deployment |
| 157 | + |
| 158 | +"Validate the deployment — run tests, check row counts, verify masking is applied." |
| 159 | + |
| 160 | +The agent runs `dbt test`, checks row and null counts, then queries the table as the `PUBLIC` role to confirm PII columns are masked (email → `*****@domain.com`, phone → `***-***-XXXX`). |
| 161 | + |
| 162 | +> **Review checkpoint:** All dbt tests pass. If any fail, CoCo consults the Error Playbook and suggests a targeted fix. |
| 163 | +
|
| 164 | +<!-- ------------------------ --> |
| 165 | +## Operate: Automated Monitoring |
| 166 | + |
| 167 | +Duration: 5 minutes |
| 168 | + |
| 169 | +The monitoring SQL was generated in Deliver Prompt 3. Open `04_operate/_example/monitoring_observability.sql` in Snowsight to review or re-run any check independently. |
| 170 | + |
| 171 | +### Prompt 1: Run Monitoring Checks |
| 172 | + |
| 173 | +Open `04_operate/_example/monitoring_observability.sql` in Snowsight and run each section in order: |
| 174 | + |
| 175 | +| Check | What it does | |
| 176 | +|-------|-------------| |
| 177 | +| **Freshness SLA** | Reports hours since last refresh; flags `SLA_BREACH` if > 24 hours | |
| 178 | +| **Quality gate** | Queries DMF metric history and reports PASS/FAIL per quality rule | |
| 179 | +| **Usage tracking** | Returns query count and compute time per role/user over the last 7 days | |
| 180 | + |
| 181 | +**RACI Template:** `04_operate/raci_template.md` provides a reusable responsibility matrix — copy and fill in for your team. |
| 182 | + |
| 183 | +<!-- ------------------------ --> |
| 184 | +## Refine: Evolve the Data Product |
| 185 | + |
| 186 | +Duration: 3 minutes |
| 187 | + |
| 188 | +### Prompt 1: Review the v2 Contract |
| 189 | + |
| 190 | +Open `05_refine/_example/churn_risk_data_contract_v2.yaml`. Two new columns have been added driven by consumer feedback. Compare with the v1 contract to see what changed — the agent will use this diff to regenerate only the affected artifacts. |
| 191 | + |
| 192 | +### Prompt 2: Regenerate Affected Artifacts |
| 193 | + |
| 194 | +"The contract has been updated to v2 with new columns. Regenerate only the affected dbt model SQL, schema.yml, and DMF setup — no full rebuild required." |
| 195 | + |
| 196 | +The agent compares the contract versions, identifies the changed sections, and regenerates only those artifacts. Review `05_refine/_example/evolution_example.sql` to see the incremental ALTER TABLE statements produced. |
| 197 | + |
| 198 | +> **Adapting to your industry:** Update any contract field — schema, quality rules, or SLAs — and re-run this prompt. Only the downstream artifacts that depend on the changed section are regenerated. |
| 199 | +
|
| 200 | +<!-- ------------------------ --> |
| 201 | +## Cleanup |
| 202 | + |
| 203 | +Duration: 2 minutes |
| 204 | + |
| 205 | +Run `06_cleanup/cleanup.sql` in Snowsight. It drops `RETAIL_BANKING_DB` and `DATA_PRODUCTS_WH`, removing all objects created by this guide. |
| 206 | + |
| 207 | +> **Note:** This permanently deletes all tables, views, stages, and data. Save any outputs you want to keep before running. |
| 208 | +
|
| 209 | +<!-- ------------------------ --> |
| 210 | +## Conclusion and Resources |
| 211 | + |
| 212 | +Duration: 2 minutes |
| 213 | + |
| 214 | +### What You Learned |
| 215 | + |
| 216 | +- How a data contract (ODCS v2.2) drives all downstream automation — one document replaces days of manual artifact authoring |
| 217 | +- How the `dplc-accelerator` skill orchestrates dbt generation, governance, deployment, and monitoring in a single sprint |
| 218 | +- How to evolve a data product by updating the contract and re-running only the affected artifacts |
| 219 | + |
| 220 | +### Related Resources |
| 221 | + |
| 222 | +- [Source repo with full example code](https://github.com/srini86/data-products-lifecycle-fsi-example) |
| 223 | +- [Cortex Code documentation](https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-code) |
| 224 | +- [dbt Core with Snowflake](https://docs.snowflake.com/en/user-guide/ecosystem-dbt) |
| 225 | +- [Data Metric Functions](https://docs.snowflake.com/en/user-guide/data-quality-intro) |
| 226 | +- [Snowflake Semantic Views](https://docs.snowflake.com/en/user-guide/views-semantic) |
| 227 | +- [Open Data Contract Standard (ODCS)](https://bitol-io.github.io/open-data-contract-standard/) |
| 228 | +- [Internal Marketplace](https://docs.snowflake.com/en/user-guide/data-exchange-internal-marketplace) |
| 229 | +- [Blog post: Building Enterprise Grade Data Products for FSI](https://datadonutz.medium.com/building-regulatory-grade-data-products-on-snowflake-for-fsi-938895e25e35) |
0 commit comments