testing-dbt-models

为 dbt 模型添加和维护 schema 测试与数据质量验证。适用于在 schema.yml 中新增或修改测试、处理提到 “test”、“validate”、“data quality”、“unique”、“not_null” 或 “accepted_values” 的任务、确保主键/外键与关系完整性,以及调试或分析 dbt 测试失败。新增测试前会遵循并匹配现有项目的测试模式与 YAML 风格。

仓库最近推送
GitHub Stars
137
Forks
13
Issues / PRs
5

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "testing-dbt-models":https://skillpi.com/zh/skills/deepskill-324e5e5ddf463ddb817825782bf9ba8b4ed177ca4671db5bf2caba5656645954。安装前核对上游来源和版本:https://github.com/AltimateAI/data-engineering-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 dbt 模型添加和维护 schema 测试与数据质量验证。适用于在 schema.yml 中新增或修改测试、处理提到 “test”、“validate”、“data quality”、“unique”、“not_null” 或 “accepted_values” 的任务、确保主键/外键与关系完整性,以及调试或分析 dbt 测试失败。新增测试前会遵循并匹配现有项目的测试模式与 YAML 风格。

0 下载

介绍来源: third_party · AltimateAI · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: testing-dbt-models
description: |
  Adds schema tests and data quality validation to dbt models. Use when working with dbt tests for:
  (1) Adding or modifying tests in schema.yml files
  (2) Task mentions "test", "validate", "data quality", "unique", "not_null", or "accepted_values"
  (3) Ensuring data integrity - primary keys, foreign keys, relationships
  (4) Debugging test failures or understanding why dbt test failed
  Matches existing project test patterns and YAML style before adding new tests.

dbt Testing

Every model deserves at least one test. Primary keys need unique + not_null.

Workflow

1. Study Existing Test Patterns

CRITICAL: Match the project's existing testing style before adding new tests.

# Find all schema.yml files with tests
find . -name "schema.yml" -exec grep -l "tests:" {} \;

# Read existing tests to learn patterns
cat models/staging/schema.yml | head -100
cat models/marts/schema.yml | head -100

# Check for custom tests or dbt packages
ls tests/
cat packages.yml 2>/dev/null

Extract from existing tests:

  • YAML formatting style (indentation, spacing)
  • Test coverage depth (all columns vs key columns only)
  • Use of custom tests (dbt_utils, dbt_expectations, custom macros)
  • Description style (brief vs detailed)
  • Severity levels used (warn vs error)

2. Read Model SQL

cat models/<path>/<model_name>.sql

Identify: primary keys, foreign keys, categorical columns, date columns, business-critical fields.

3. Check Existing Tests for This Model

cat models/<path>/schema.yml | grep -A 50 "<model_name>"
# or
find . -name "schema.yml" -exec grep -l "<model_name>" {} \;

4. Identify Testable Columns

Column Type Recommended Tests
Primary key unique, not_null
Foreign key not_null, relationships
Categorical accepted_values (ask user for valid values)
Required field not_null
Date/timestamp not_null
Boolean accepted_values: [true, false]

5. Write Tests in schema.yml

Match the existing style from step 1. Example format (adapt to project):

version: 2

models:
  - name: model_name
    description: "Brief description of what this model contains"
    columns:
      - name: primary_key_column
        description: "Unique identifier for this record"
        tests:
          - unique
          - not_null

      - name: foreign_key_column
        description: "Reference to related_model"
        tests:
          - not_null
          - relationships:
              to: ref('related_model')
              field: related_key_column

      - name: status
        description: "Current status of the record"
        tests:
          - not_null
          - accepted_values:
              values: ['pending', 'active', 'completed', 'cancelled']

      - name: created_at
        description: "Timestamp when record was created"
        tests:
          - not_null

6. Run Tests

# Test specific model
dbt test --select <model_name>

# Test with upstream
dbt test --select +<model_name>

7. Fix Failing Tests

Common failures and fixes:

Failure Likely Cause Fix
unique fails Duplicate records Add deduplication in model
not_null fails NULL values in source Add COALESCE or filter
relationships fails Orphan records Add WHERE clause or fix upstream
accepted_values fails New/unexpected values Update accepted values list

Test Types Reference

Generic Tests (built-in)

tests:
  - unique
  - not_null
  - accepted_values:
      values: ['a', 'b', 'c']
  - relationships:
      to: ref('other_model')
      field: id

Custom Generic Tests

tests:
  - dbt_utils.expression_is_true:
      expression: "amount >= 0"
  - dbt_utils.recency:
      datepart: day
      field: created_at
      interval: 1

Singular Tests

Create tests/<test_name>.sql:

-- tests/assert_positive_revenue.sql
select *
from {{ ref('orders') }}
where revenue < 0

Anti-Patterns

  • Adding tests without checking existing project patterns first
  • Using different YAML formatting style than existing tests
  • Models without any tests
  • Primary keys without both unique AND not_null
  • Testing only obvious columns, ignoring business-critical ones
  • Hardcoding accepted_values without confirming with stakeholders
  • Adding dbt_utils tests when project doesn't use that package

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供完整的 dbt 测试工作流,从模式匹配到测试编写再到失败修复
触发精准95/100

亮点

  • 触发词精准覆盖 dbt 测试核心场景,包括 schema.yml 操作、数据质量关键词等
结构规范90/100

亮点

  • Phase 划分清晰,包含端到端示例和防错机制
执行可靠93/100

亮点

  • 命令准确,覆盖主要异常场景,强调风格匹配和项目一致性
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。