0 0
Read Time:10 Minute, 16 Second

Claude Meets Snowflake DMF: AI Takes Action: In my previous article, Stop Writing Data Quality Scripts. Start Writing Metadata., I demonstrated a metadata-driven framework using Snowflake Data Metric Functions (DMF).

The framework provided a centralized way to configure data quality rules, dynamically attach DMFs, execute validations on demand, and capture audit results and alerts.

The POC worked successfully.

Nine quality rules were configured across two tables, CUSTOMER and ORDERS, using a combination of Snowflake built-in and custom DMFs.

But after completing that implementation, I started thinking about the next challenge.

What if a data engineer, analyst, or support team member could simply ask:

  • “What is the latest data quality status?”
  • “Which CUSTOMER rules are failing?”
  • “How many violations were reported?”
  • “Run all active data quality checks again.”
  • “Did the execution succeed?”

Turn a metadata-driven data quality framework into an AI-powered data quality operations assistant.

Capability 1 – Conversational Data Quality Analytics

A user should be able to ask natural-language questions about quality metrics without writing SQL.

For example:

Which tables have failing data quality rules?

The assistant should retrieve actual Snowflake measurements, identify the affected tables, and return an understandable explanation.

Capability 2 – Agentic Data Quality Execution

A user should be able to request an operation:

Run all active data quality checks and tell me whether the execution succeeded.

The assistant should recognize this as an execution request, invoke the appropriate Snowflake tool, and report the actual outcome.

This is the key difference.

Reading data through AI is useful. Allowing AI to select and execute a controlled operational tool makes the solution substantially more interesting.

The Architecture: Snowflake Intelligence, External AI Interface

The design uses six main components.

  • The most important architectural decision was to keep the data quality business logic inside Snowflake.
  • Claude would be our conversational interface.
  • The Cortex Agent would decide which Snowflake capability to use.
  • The existing framework would remain responsible for measuring data quality.

End-to-end architecture

Step 1 – Reuse the Existing DMF Framework

The first rule for this POC was simple: don’t rewrite something that already works.

It already contained the important objects:

Our original execution procedure could already be called using:

CALL DMF_DB.PUBLIC.RUN_DMFS_MANUALLY_FULL();

The agentic extension would reuse this procedure instead of duplicating the validation logic.

Step 2 – Create a Reporting View for the Latest Results

Our audit table stores historical measurements. That is useful, but it introduces a challenge for AI analytics.

If nine checks execute five times, the audit table may contain 45 measurement records.

When a user asks:

What is our current data quality status?

The assistant should not blindly count all 45 records.

It should retrieve the most recent measurement for each configured rule. To address this, I created:

VW_DQ_LATEST

Core reporting logic

CREATE OR REPLACE VIEW DMF_DB.PUBLIC.VW_DQ_LATEST AS

WITH LATEST_AUDIT AS (
    SELECT
        TABLE_NAME,
        RULE_NAME,
        METRIC_NAME,
        METRIC_COUNT,
        MEASUREMENT_TIME
    FROM DMF_DB.PUBLIC.DATA_QUALITY_AUDIT_LOG

    QUALIFY ROW_NUMBER() OVER (
        PARTITION BY TABLE_NAME, RULE_NAME
        ORDER BY MEASUREMENT_TIME DESC
    ) = 1
)

SELECT
    M.TABLE_NAME,
    M.RULE_NAME,
    M.COLUMN_NAME,
    M.DMF_NAME,
    M.DMF_TYPE,
    A.METRIC_COUNT,
    A.MEASUREMENT_TIME,

    CASE
        WHEN A.MEASUREMENT_TIME IS NULL THEN 'NOT_RUN'
        WHEN A.METRIC_COUNT > 0 THEN 'ISSUE'
        ELSE 'PASS'
    END AS QUALITY_STATUS

FROM DMF_DB.PUBLIC.DMF_METADATA M

LEFT JOIN LATEST_AUDIT A
    ON M.TABLE_NAME = A.TABLE_NAME
   AND M.RULE_NAME = A.RULE_NAME

WHERE M.ACTIVE_FLAG = 'Y'
  AND M.MODE_OF_DMF = 'FULL';

Why this view matters

The ROW_NUMBER() logic identifies the latest available measurement for each table and rule.

The status calculation then converts the numeric measurement into a simple business classification:

  • PASS — Zero violations.
  • ISSUE — One or more violations.
  • NOT_RUN — No recorded measurement.

Step 3 – Add Business Meaning with a Semantic View

This is where the solution becomes ready for natural-language analytics.A Snowflake Semantic View adds business meaning through dimensions and metrics.

For example, when someone asks:

How many quality checks failed?

The AI needs to understand that a failed quality rule is represented by:

QUALITY_STATUS = 'ISSUE'

To model this, created:

DMF_DB.PUBLIC.SV_DATA_QUALITY

Key Semantic View definition

CREATE OR REPLACE SEMANTIC VIEW
DMF_DB.PUBLIC.SV_DATA_QUALITY

TABLES (
    quality AS DMF_DB.PUBLIC.VW_DQ_LATEST
)

DIMENSIONS (
    quality.table_name
        AS quality.TABLE_NAME,

    quality.rule_name
        AS quality.RULE_NAME,

    quality.quality_status
        AS quality.QUALITY_STATUS,

    quality.measurement_time
        AS quality.MEASUREMENT_TIME
)

METRICS (
    quality.total_rules AS COUNT(*),

    quality.failed_rules AS
        COUNT_IF(quality.QUALITY_STATUS = 'ISSUE'),

    quality.passed_rules AS
        COUNT_IF(quality.QUALITY_STATUS = 'PASS'),

    quality.total_violations AS
        SUM(COALESCE(quality.METRIC_COUNT, 0))
);

We are defining how the AI should interpret our data quality measurements.

For example:

Failed Rules = Number of rules reporting violations.

Total Violations = Sum of reported violations across rules.

Step 4 – Build the Execution Tool

A Semantic View and Cortex Analyst can answer questions about data.But neither, by itself, provides the operational tool we needed to run our existing DMF framework.

For that, I created a small JavaScript stored procedure:

SP_EXECUTE_DQ_RUN()

It would:

  1. Call our existing manual DMF procedure.
  2. Capture the returned execution summary.
  3. Determine whether the execution completed successfully.
  4. Return a structured JSON response.

The execution wrapper

CREATE OR REPLACE PROCEDURE DMF_DB.PUBLIC.SP_EXECUTE_DQ_RUN()
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
try {

    var stmt = snowflake.createStatement({
        sqlText: `
            CALL DMF_DB.PUBLIC.RUN_DMFS_MANUALLY_FULL()
        `
    });

    var rs = stmt.execute();
    rs.next();

    var summary = String(rs.getColumnValue(1));

    var match = summary.match(/Failed:\s*(\d+)/);

    if (!match) {
        throw new Error(
            'Unable to verify execution: ' + summary
        );
    }

    var failed = Number(match[1]);

    return JSON.stringify({
        status: failed === 0 ? 'SUCCESS' : 'FAILED',
        summary: summary
    });

} catch (err) {

    return JSON.stringify({
        status: 'FAILED',
        error: String(err.message)
    });
}
$$;

Notice that this wrapper contains no data quality rules.The wrapper is simply a controlled interface for invoking that capability and reporting the outcome.

The actual POC result

The wrapper returned:

{
  "status": "SUCCESS",
  "summary": "Rules: 9 | Successful: 9 | Alerts: 7 | Failed: 0"
}

This confirmed that the framework could be invoked through an additional procedure without changing the underlying DMF implementation.

Step 5 – Create One Cortex Agent with Two Tools

At this point, we had both capabilities ready:

Tool 1 — QualityAnalyst: Answer data quality questions using our Semantic View.

Tool 2 — ExecuteDQChecks: Invoke our existing manual execution framework through the wrapper.

The next step was to bring both together under a single Cortex Agent:

DQ_OPERATIONS_AGENT

The agent configuration

The key parts of the configuration are shown below.

models:
  orchestration: auto

instructions:
  response: >
    You are a Snowflake Data Quality Assistant.Answer using actual Snowflake measurements.Distinguish quality violations from
    execution failures.

  orchestration: >
    Use QualityAnalyst for questions about quality status and rule measurements.

    Use ExecuteDQChecks only when the user explicitly requests a new quality run.

    Ask for confirmation before execution.

    Report the actual tool response.

tools:
  - tool_spec:
      type: cortex_analyst_text_to_sql
      name: QualityAnalyst
      description: >
        Answers questions about data quality.

  - tool_spec:
      type: generic
      name: ExecuteDQChecks
      description: >
        Executes active data quality checks.
      input_schema:
        type: object
        properties: {}

tool_resources:
  QualityAnalyst:
    semantic_view: DMF_DB.PUBLIC.SV_DATA_QUALITY
    execution_environment:
      type: warehouse
      warehouse: CI_WH
      query_timeout: 60

  ExecuteDQChecks:
    type: procedure
    identifier: DMF_DB.PUBLIC.SP_EXECUTE_DQ_RUN
    execution_environment:
      type: warehouse
      warehouse: CI_WH
      query_timeout: 300

Why use one agent?

The user shouldn’t need to know which Snowflake object handles which question.

For example:

User: “Which CUSTOMER rules failed?”

The agent selects QualityAnalyst.

User: “Run all data quality checks again.”

The agent selects ExecuteDQChecks.

That tool-selection capability is the heart of our agentic workflow.

Step 6 – Expose the Cortex Agent Through MCP

The next question was:

How can Claude, an external AI assistant, interact with our Snowflake Cortex Agent?

This is where the Model Context Protocol (MCP) enters the picture.

Instead of developing a custom REST API, building a separate Python MCP server, or hosting our own middleware, we used Snowflake’s managed MCP Server capability.

I created:

DMF_DB.PUBLIC.DQ_MCP_SERVER

MCP Server definition

CREATE OR REPLACE MCP SERVER DMF_DB.PUBLIC.DQ_MCP_SERVER
FROM SPECIFICATION
$$
tools:
  - name: "data_quality_advisor"
    title: "Snowflake Data Quality Advisor"
    type: "CORTEX_AGENT_RUN"
    identifier: "DMF_DB.PUBLIC.DQ_OPERATIONS_AGENT"
    description: >
      Answers questions about Snowflake data
      quality and supports authorized
      execution of active quality checks.
$$;

Notice something important.

  • The MCP Server exposes one Cortex Agent, not separate endpoints for every internal function.
  • The agent already knows how to route requests between Cortex Analyst and the execution procedure.
  • The server becomes accessible through an authenticated endpoint following this pattern:
https://<snowflake-account-host>/api/v2/databases/DMF_DB/schemas/PUBLIC/mcp-servers/DQ_MCP_SERVER
  • Our AI assistant could now communicate with the Snowflake Agent through MCP.

Step 7 – Configure Snowflake OAuth for Claude

This was an especially valuable learning experience.An MCP connection isn’t just about supplying a URL. The external AI client needs to authenticate to Snowflake, and Snowflake must determine which role that client can use.

OAuth configuration

CREATE SECURITY INTEGRATION MCP_DEMO_OAUTH_INT
    TYPE = OAUTH
    OAUTH_CLIENT = CUSTOM
    ENABLED = TRUE
    OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'
    OAUTH_REDIRECT_URI =
        'https://claude.ai/api/mcp/auth_callback'
    OAUTH_ISSUE_REFRESH_TOKENS = TRUE
    OAUTH_REFRESH_TOKEN_VALIDITY = 7776000;

Restricting OAuth roles

I subsequently configured the integration to allow the dedicated POC role:

ALTER SECURITY INTEGRATION MCP_DEMO_OAUTH_INT
SET
    ALLOWED_ROLES_LIST = ('DQ_MCP_READ_ROLE'),
    PRE_AUTHORIZED_ROLES_LIST =
        ('DQ_MCP_READ_ROLE');

In our case, Claude connected using DQ_MCP_READ_ROLE, not the ACCOUNTADMIN role used during development.

Step 8 – Connect Claude to Snowflake MCP

With the MCP Server and OAuth integration ready, I configured a custom remote MCP connector in Claude.

The connector used:

  • The Snowflake MCP endpoint.
  • The OAuth client ID.
  • The OAuth client secret.
  • Snowflake’s OAuth authorization flow.

I first tested a read-only question:

Show me the latest data quality status for CUSTOMER and ORDERS.

Claude successfully retrieved the measurements through:

Claude → MCP → Cortex Agent → Cortex Analyst → Semantic View

The assistant identified seven issue-reporting rules and two passing duplicate-key rules.

Our first external AI use case was working.

Then I tested the more interesting one.

The Real Test: Ask Claude to Execute the DMFs

I asked Claude:

Run all active Snowflake data quality checks and tell me how many passed, how many reported issues, and whether the execution succeeded.

Inside Snowsight, I had tested the procedure using ACCOUNTADMIN. But Claude connected through OAuth using: DQ_MCP_READ_ROLE

That role had permission to access the MCP Server, Cortex Agent, Semantic View, and warehouse. It did not initially have the required procedure execution privileges.

I granted the POC role permission to invoke the execution wrapper and the underlying DMF procedure:

GRANT USAGE ON PROCEDURE
DMF_DB.PUBLIC.SP_EXECUTE_DQ_RUN()
TO ROLE DQ_MCP_READ_ROLE;

GRANT USAGE ON PROCEDURE
DMF_DB.PUBLIC.RUN_DMFS_MANUALLY_FULL()
TO ROLE DQ_MCP_READ_ROLE;

Because these procedures use EXECUTE AS CALLER, the role also needed the relevant privileges on the metadata, source tables, custom DMFs, audit table, and alerts table.

For example:

GRANT SELECT, UPDATE ON TABLE
DMF_DB.PUBLIC.DMF_METADATA
TO ROLE DQ_MCP_READ_ROLE;

GRANT INSERT ON TABLE
DMF_DB.PUBLIC.DATA_QUALITY_AUDIT_LOG
TO ROLE DQ_MCP_READ_ROLE;

GRANT INSERT ON TABLE
DMF_DB.PUBLIC.DATA_QUALITY_ALERTS
TO ROLE DQ_MCP_READ_ROLE;


What Makes This Approach Different?

  • This is the central value of the POC. I did not build a new set of AI-specific data quality checks (DMF).
  • I connected AI to a framework that was already metadata-driven and operationally reusable.
  • The resulting architecture combines two automation layers.

Layer 1 – Metadata-driven quality execution

The original framework uses metadata to configure and execute checks.

Developers can register supported rules without creating individual execution scripts for each table.

Layer 2 – Agent-driven operations

The Cortex Agent uses tools to answer questions and trigger an existing capability.

Claude becomes an external conversational interface, while Snowflake remains the execution and governance platform.

 

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *