Snowflake-Labs/cortex-ai-eval-pipeline
Python
Captured source
source ↗Snowflake-Labs/cortex-ai-eval-pipeline
Description: Reference implementation of offline and online evaluation for production AI systems using Snowflake Cortex AI.
Language: Python
License: Apache-2.0
Stars: 0
Forks: 0
Open issues: 0
Created: 2026-11-06T04:03:07Z
Pushed: 2026-11-10T22:59:24Z
Default branch: main
Fork: no
Archived: no
README:
cortex-ai-eval-pipeline
A reference implementation of offline and online evaluation for production AI systems, built as a dbt pipeline on Snowflake Cortex AI.
The problem
A successful AI inference does not mean the output is safe to consume. Production AI has three distinct quality questions:
1. Offline evaluation: Is this code/prompt/model change safe to deploy? 2. Online evaluation: Is this production batch safe to publish to downstream consumers? 3. Monitoring: Is accuracy drifting on real production data over time?
These are different questions, answered at different times, by different mechanisms. This project implements all three in a single dbt pipeline, making evaluation mandatory by construction.
Architecture
OFFLINE EVALUATION (CI/CD) Golden dataset (fixed, labeled) --> Full pipeline + LLM judge --> Accuracy vs stored baseline --> Blocks PR merge if regression detected ONLINE EVALUATION (Every production run) Input Quality: Source --> Profiling --> Eligibility --> Inference Output Quality: Format Check + LLM Judge --> Aggregate Metrics --> Quality Gate | Publication (if PASS) MONITORING (Feedback loop) Delayed labels arrive --> Retroactive accuracy computed --> Review accuracy trend (manual) --> Update golden dataset --> Re-enter offline evaluation
Online evaluation uses behavioral metrics (no labels needed). Offline evaluation uses accuracy metrics (labels from golden dataset). Monitoring bridges the gap with delayed labels.
Prerequisites
- Snowflake account with Cortex AI access
- Python 3.10+ (tested on 3.12)
- dbt-core >= 1.10.5, dbt-snowflake >= 1.10 (tested on 1.12, pinned in
requirements.txt) - Cortex models:
mistral-large2(classifier),claude-sonnet-4-5(judge)
Setup
git clone https://github.com/Snowflake-Labs/cortex-ai-eval-pipeline.git cd cortex-ai-eval-pipeline python -m venv .venv source .venv/bin/activate pip install -r requirements.txt dbt deps
Configure your Snowflake connection:
cp .env.example .env # Edit .env with your Snowflake account details
| Variable | Required | Default | |----------|----------|---------| | SNOWFLAKE_ACCOUNT | Yes | -- | | SNOWFLAKE_USER | Yes | -- | | SNOWFLAKE_PRIVATE_KEY_PATH | Yes | -- | | SNOWFLAKE_ROLE | Yes | -- (use a least-privilege role, see below) | | SNOWFLAKE_WAREHOUSE | No | COMPUTE_WH | | SNOWFLAKE_DATABASE | No | LLM_PIPELINE_PROD |
> Recent dbt versions read .env from the project directory, but older ones and scripts/check_gate.py do not. Source it before running: > ``bash > source .env && export SNOWFLAKE_ACCOUNT SNOWFLAKE_USER SNOWFLAKE_PRIVATE_KEY_PATH SNOWFLAKE_ROLE SNOWFLAKE_WAREHOUSE SNOWFLAKE_DATABASE >
Authentication is key-pair only, for both dbt and scripts/check_gate.py.
Least-privilege role
Run the pipeline with a dedicated role rather than SYSADMIN (access control considerations). It needs to own the two pipeline databases, use one warehouse, and call AI_COMPLETE, which requires the USE AI FUNCTIONS privilege plus the CORTEX_USER (or AI_FUNCTIONS_USER) database role (Cortex privileges). Both are granted to PUBLIC by default; grant them explicitly if your account has revoked that.
USE ROLE ACCOUNTADMIN; CREATE ROLE IF NOT EXISTS LLM_PIPELINE_ROLE; CREATE DATABASE IF NOT EXISTS LLM_PIPELINE_CI; CREATE DATABASE IF NOT EXISTS LLM_PIPELINE_PROD; GRANT OWNERSHIP ON DATABASE LLM_PIPELINE_CI TO ROLE LLM_PIPELINE_ROLE; GRANT OWNERSHIP ON DATABASE LLM_PIPELINE_PROD TO ROLE LLM_PIPELINE_ROLE; GRANT USAGE ON WAREHOUSE COMPUTE_WH TO ROLE LLM_PIPELINE_ROLE; GRANT USE AI FUNCTIONS ON ACCOUNT TO ROLE LLM_PIPELINE_ROLE; GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE LLM_PIPELINE_ROLE; GRANT ROLE LLM_PIPELINE_ROLE TO USER ;
Seed data
All input data is stored as dbt seed CSVs under seeds/. Each seed is tagged so the correct subset loads per environment.
| Seed | Used in | Description | |------|---------|-------------| | golden_tickets.csv | Offline | 40 labeled tickets with known-correct categories. Used as ground truth for regression testing. | | baseline_metrics.csv | Offline | 3 accuracy baselines. Offline evaluation flags regressions against these. | | production_tickets.csv | Online | 20 unlabeled tickets for live classification. | | evaluation_thresholds.csv | Online | 4 quality gate thresholds (e.g., max invalid_output_rate, max judge_flag_rate). | | delayed_labels.csv | Monitoring | 17 human labels that arrive after predictions are published. Joined to compute retroactive accuracy. |
Run: offline evaluation
Purpose: Is this prompt/model change safe to deploy?
This runs as part of the CI workflow (.github/workflows/ci.yml):
DBT_PROFILES_DIR=. dbt build --target ci --full-refresh --exclude tag:runtime tag:monitoring
--target ci points to the LLM_PIPELINE_CI database and swaps the source to golden_tickets (40 labeled tickets). --exclude tag:runtime tag:monitoring strips out production-only models (quality gate, publication, run history) and deferred monitoring (retroactive accuracy).
> All PRs share the LLM_PIPELINE_CI database, so CI runs the Snowflake job one PR at a time (a global concurrency group), and the regression gate only reads rows from its own dbt run. GitHub keeps only the newest waiting run in a group, so if several PRs queue at once an older waiting run is cancelled and needs a re-run.
> Pull requests from forks get no repository secrets, so they run lint and dbt parse only; the Snowflake gate runs on PRs from branches in this repository.
This materializes the following tables in LLM_PIPELINE_CI:
1. Eligibility — PIPELINE.ELIGIBILITY_CHECK rejects invalid records before they reach inference (empty text, too short, unsupported language) 2. Inference — PIPELINE.CLASSIFY_TICKET...
Excerpt shown — open the source for the full document.