Step by Step Writing An Entitle Data Quality Skill

Step by step build a complete Data Quality Skill from scratch.
“Please analyze this Excel file and give me a data quality report.”
we will build skill like this.

data-quality-skill/
│
├── SKILL.md
│
├── scripts/
│   ├── profile_excel.py
│   ├── check_nulls.py
│   ├── check_duplicates.py
│   └── generate_report.py
│
├── references/
│   └── data-quality-rules.md
│
└── resources/
    └── report_template.md

2. Design the capability first, then the workflow, and then the scripts.

3. Agent 到底要完成什么任务?

Agent should do:

  • Identify the input file – 找到输入文件
  • Profile the dataset – Profile 数据集
  • Check NULL values – 检查 NULL
  • Check duplicate rows – 检查重复
  • Check basic schema – 检查基本 Schema
  • Interpret the results – 解释结果
  • Generate a report – 生成报告

4. Design Workflow

User Request   用户请求
     ↓
Identify Input   确定输入
     ↓
Profile Dataset   分析数据集
     ↓
Run Quality Checks   执行质量检查
     ├── NULL check   NULL 检查
     ├── Duplicate check   重复检查
     └── Schema check   Schema 检查
     ↓
Interpret Results   解释结果
     ↓
Generate Report   生成报告

5. 第一步:创建目录

</> Bash

mkdir -p data-quality-skill/scripts
mkdir -p data-quality-skill/references
mkdir -p data-quality-skill/resources

## looks this (SKILL.md is file rather than directory)

data-quality-skill/
├── SKILL.md
├── scripts/
├── references/
└── resources/

6. 第二步:profile_excel.py

我们先做第一个真正的执行工具, 它负责:获取数据事实。

</> Python

"""
profile_excel.py

Purpose / 目的:
    Profile an Excel dataset and return deterministic statistics.
    对 Excel 数据集进行 Profile,并返回确定性的统计结果。

Why this script exists / 为什么需要这个脚本:
    The LLM should reason about data-quality results,
    but it should NOT manually calculate dataset statistics.

    LLM 应该负责解释数据质量结果,
    而不是自己手工计算数据统计信息。
"""

from pathlib import Path
import json
import sys

import pandas as pd


def profile_excel(file_path: str) -> dict:
    """
    Read an Excel file and calculate basic profiling information.

    读取 Excel 文件并计算基础 Profile 信息。
    """

    # ---------------------------------------------------------
    # Validate the input path.
    # 验证输入文件路径。
    # ---------------------------------------------------------
    path = Path(file_path)

    if not path.exists():
        raise FileNotFoundError(
            f"File does not exist: {file_path}"
        )

    # ---------------------------------------------------------
    # Read the Excel file.
    # 读取 Excel 文件。
    #
    # pandas performs deterministic data processing.
    # pandas 执行确定性的数据处理。
    # ---------------------------------------------------------
    df = pd.read_excel(path)

    # ---------------------------------------------------------
    # Build structured profiling results.
    # 构建结构化 Profile 结果。
    #
    # The result is deliberately JSON-friendly.
    # 结果故意设计成 JSON-friendly 格式。
    # ---------------------------------------------------------
    result = {
        # Total number of rows.
        # 总行数。
        "row_count": int(len(df)),

        # Total number of columns.
        # 总列数。
        "column_count": int(len(df.columns)),

        # Column names.
        # 列名。
        "columns": list(df.columns),

        # Data type of every column.
        # 每一列的数据类型。
        "data_types": {
            column: str(dtype)
            for column, dtype in df.dtypes.items()
        },

        # NULL count for every column.
        # 每一列的 NULL 数量。
        "null_counts": {
            column: int(count)
            for column, count in df.isnull().sum().items()
        },

        # Total number of completely duplicated rows.
        # 完全重复的行数量。
        "duplicate_rows": int(df.duplicated().sum()),
    }

    return result


def main():
    """
    Command-line entry point.
    命令行程序入口。

    This makes the script independently executable.
    这样这个脚本可以独立执行。
    """

    # ---------------------------------------------------------
    # Validate command-line arguments.
    # 验证命令行参数。
    # ---------------------------------------------------------
    if len(sys.argv) != 2:
        print(
            "Usage: python profile_excel.py <excel_file>",
            file=sys.stderr
        )
        sys.exit(1)

    file_path = sys.argv[1]

    try:
        # -----------------------------------------------------
        # Execute the profiling logic.
        # 执行 Profile 逻辑。
        # -----------------------------------------------------
        result = profile_excel(file_path)

        # -----------------------------------------------------
        # Convert Python dictionary into JSON.
        # 把 Python dictionary 转换成 JSON。
        #
        # JSON is easy for Agents and other programs to consume.
        # JSON 很容易被 Agent 和其他程序消费。
        # -----------------------------------------------------
        print(
            json.dumps(
                {
                    "status": "success",
                    "data": result
                },
                indent=2
            )
        )

    except Exception as exc:

        # -----------------------------------------------------
        # Return structured error information.
        # 返回结构化错误信息。
        # -----------------------------------------------------
        print(
            json.dumps(
                {
                    "status": "error",
                    "error": str(exc)
                },
                indent=2
            ),
            file=sys.stderr
        )

        sys.exit(1)


# -------------------------------------------------------------
# Only execute main() when this file is run directly.
# 只有直接运行这个文件时才执行 main()。
# -------------------------------------------------------------
if __name__ == "__main__":
    main()

SKILL.md Specification: File Structure & description

SKILL.md is a standardized markdown file that defines a specific “capability” or “skill” for an AI Agent. It is the “user manual” that tells the LLM exactly what a particular tool/function can do, when to use it, how to use it, and what the expected output looks like. It turns a raw Python function into a teachable, reusable “expertise” for the Agent.
A in CN: SKILL.md 是一个标准化的 Markdown 文件,用于为 AI Agent 定义一项特定的“能力”或“技能”。它是给 LLM 看的“用户手册”,准确告诉模型某个工具/函数能做什么、何时使用、如何使用以及预期的输出长什么样。它把一个原始的 Python 函数变成一个可教学、可复用的 Agent “专长”。

Content and Structure of SKILL.md

A complete SKILL.md typically contains 5 core sections. Each section plays a specific role in guiding the LLM’s behavior.
A in CN: 一个完整的 SKILL.md 通常包含 5 个核心部分。每个部分在引导 LLM 行为方面都扮演着特定的角色。

SKILL.md 本质上可以理解成:

给 Agent 的一份“能力说明 + 使用说明 + 行为规则 + 操作流程”。

SKILL.md

├── 我是谁? → Skill Identity
├── 我什么时候应该被使用? → Description / Trigger
├── 我能做什么? → Capabilities
├── 我应该怎么做? → Instructions / Workflow
├── 有哪些限制? → Constraints
├── 我需要什么资源? → Resources
└── 最终应该输出什么? → Output / Examples

1. YAML Frontmatter

元数据头

This is a mandatory YAML block at the very top of the file, enclosed by ---. It contains machine-readable metadata. The most critical field here is description.
A in CN: 这是文件最顶部的强制 YAML 块,由 --- 包围。它包含机器可读的元数据。这里最关键的字段是 description。

2. Description

描述 – 本单元核心!

This is a concise, high-signal, keyword-rich sentence or two that tells the LLM’s router (the top-level orchestrator) what this skill does and when to trigger it. It is the “sales pitch” for the skill. The orchestrator reads all descriptions of all available skills and selects the most relevant one for the user’s query. If your description is vague, the orchestrator will never choose it.
CN: 这是一到两句简洁、高信号、关键词丰富的句子,告诉 LLM 的路由器(顶层编排器)这个技能做什么以及何时触发它。它是该技能的“推销词”。编排器会读取所有可用技能的所有描述,并为用户的查询选择最相关的一个。如果你的描述含糊不清,编排器永远不会选择它。

3. Steps

执行步骤

A numbered list of clear, atomic, actionable instructions for the Agent to execute. The Agent will follow these steps sequentially. This is where you break down a complex task into a workflow.
CN: 一个编号列表,包含清晰、原子化、可操作的指令供 Agent 执行。Agent 将按顺序遵循这些步骤。这是你将复杂任务分解为工作流的地方。

4. Examples

示例

 At least 2-3 concrete examples of user inputs and expected outputs (or thought processes). Examples are extremely powerful for LLMs (few-shot learning within the skill). They align the model’s output style and logic to your expectation.
CN: 至少 2-3 个具体的用户输入和预期输出(或思考过程)的示例。示例对 LLM 极其有效(技能内的 few-shot 学习)。它们使模型的输出风格和逻辑与你的期望保持一致。

5. Constraints / Safety

约束/安全

Explicit boundaries, disallowed actions, and failure handling. This is the “guardrails” section.
CN: 明确的边界、禁止的操作和失败处理。这是“护栏”部分。

Step by Step to build a skill.md

1. The most important understanding

SKILL.md 本质上可以理解成:

给 Agent 的一份“能力说明 + 使用说明 + 行为规则 + 操作流程”。

SKILL.md

├── 我是谁? → Skill Identity
├── 我什么时候应该被使用? → Description / Trigger
├── 我能做什么? → Capabilities
├── 我应该怎么做? → Instructions / Workflow
├── 有哪些限制? → Constraints
├── 我需要什么资源? → Resources
└── 最终应该输出什么? → Output / Examples

假设我们要创建一个:Excel Data Analysis Skill
它帮助 Agent 分析 Excel 文件。那么最简单的 SKILL.md 骨架可以先写成:

2. Build a skeleton

---
name: excel-data-analysis
description: Analyze Excel files and produce data quality findings, summaries, and insights.
---

# Excel Data Analysis

## Purpose

...

## When to Use

...

## Capabilities

...

## Instructions

...

## Constraints

...

## Resources

...

## Output Format

...

## Examples

...

3. YAML Frontmatter

可以理解成这个 Skill 的“身份证”。

</> YAML
---
name: excel-data-analysis
description: Analyze Excel files and produce data quality findings, summaries, and insights.
---

3.1 name

</> YAML
name: excel-data-analysis

这是非常重要的。告诉 Skill 系统:这个 Skill 叫什么?
e.g.
excel-data-analysis
sql-optimization
pdf-processing
data-quality
azure-data-engineering

3.2 description

</> YAML
description: Analyze Excel files and produce data quality findings, summaries, and insights.

这个更加重要。它告诉 Agent:这个 Skill 是干什么的,以及什么时候可能需要它。

例如用户说:”Please analyze this Excel file and find duplicate records.”

Agent 就可以判断:

User request
     ↓
Excel analysis?
     ↓
Yes
     ↓
excel-data-analysis Skill

所以:

  • name 解决:Who are you?
  • description 解决:What are you for?

4. Purpose

</> Markdown
# Excel Data Analysis

## Purpose

This skill provides a structured workflow for analyzing Excel
files, identifying data quality issues, and producing
business-oriented findings.

这里是在告诉 Agent:这个 Skill 的总体目标是什么?

Purpose 和 description 不完全一样。

  • Description: 偏向 “什么时候应该考虑使用我?” e.g. Analyze Excel files…
  • Purpose: 偏向 “使用我以后,我到底要完成什么事情?”
    e.g identify data quality issues
    produce business-oriented findings

5. When to Use

</> Markdown

## When to Use

Use this skill when the user asks to:

- Analyze an Excel workbook
- Profile columns and data types
- Detect missing values
- Detect duplicate records
- Identify inconsistent values
- Produce data quality findings

这个 section 非常关键。它解决:什么时候应该启动这个 Skill?

所以这里实际上是在定义:Trigger conditions. 可以把它理解成:Skill 的适用边界。

6. Capabilities

</> Markdown

## Capabilities

This skill can:

1. Inspect workbook structure
2. Profile columns
3. Detect missing values
4. Detect duplicates
5. Detect inconsistent values
6. Generate a data quality summary

这个 section 解决的是:这个 Skill 到底“会什么”?

  • When to Use 回答:什么时候用我?
  • Capabilities 回答:用了我以后,我能干什么?

7. Instructions

现在进入最核心的部分。在不同的文章里可能叫不同的名字。 例如:WorkflowInstructionsSteps。反正都是告诉 Agent 如何 一步一步地去做什么,具体怎么做。Instructions 是一个更大的概念。Instructions 可以描述 Workflow,也可以描述规则、约束、方法、注意事项等。
Instructions can describe the Workflow, as well as rules, constraints, methods, and other guidance.

如果细化一下:

概念ENCN
InstructionsThe actual guidance/rules for performing the task完成任务时应该遵循的指导和规则
WorkflowThe overall sequence/flow of the work整个工作的流程
StepOne individual stage/action within the workflowWorkflow 中的一个具体步骤

Why can’t we just write one sentence?- “Analyze the Excel file and generate a data quality report.”

This sentence is not wrong. But it does not specify:

What should happen first?
What should happen next?
What should be checked?
When should processing stop?
When should processing continue?
How should the result be validated?
What should the final output contain?

</> Markdown

## Instructions

Follow these steps:

### Step 1: Inspect the workbook

Identify:

- Workbook name
- Sheet names
- Number of rows
- Number of columns
- Column names

### Step 2: Profile the data

For each column:

- Determine data type
- Calculate null count
- Calculate distinct count
- Identify suspicious values

### Step 3: Check data quality

Check for:

- Missing values
- Duplicate records
- Invalid formats
- Inconsistent categorical values

### Step 4: Summarize findings

Rank issues by:

1. Severity
2. Business impact
3. Number of affected records

这就是:Agent 到底应该怎么执行这个 Skill。
这才是 SKILL.md 最核心的价值。它给出了 Agent 一个做事的步骤,第一步做什么,第二步做什么,接下来做什么,,,,,,

7.1 What should a good Step contain?

内容ENCN
Step 名称Step name这一步叫什么
目的Objective为什么做这一步
输入Input这一步需要什么
操作Actions这一步做什么
判断Conditions什么情况下怎么处理
输出Output这一步产生什么

The most important principle: Be specific, actionable, and verifiable. 具体、可操作、可检查。

7.2 Step granularity

Step 的粒度. 每一个 Step 都代表一个有意义的工作阶段

Each Step represents a meaningful phase of work.
A Step can contain substeps 里面可以有子步骤. e.g.

### Step 3 — Detect Data Quality Issues

Check the following categories:

1. Missing values
   - Calculate null count.
   - Calculate null percentage.

2. Duplicates
   - Detect duplicate rows.
   - Detect duplicate business keys when defined.

3. Data types
   - Compare actual types with expected types.

4. Invalid values
   - Check values against available business rules.

7.3 Steps can contain conditions

Step 可以有条件. e.g.

### Step 4 — Validate Findings

1. If a business rule is available:
   - Validate the data against the rule.

2. If no business rule is available:
   - Report the observed anomaly.
   - Do not assume that the anomaly is a business error.

3. If the evidence is insufficient:
   - Do not report a definitive violation.
   - Mark the finding as requiring confirmation.

因此好的 Step 可以包含:

  • If
  • When
  • Unless
  • Otherwise

这些条件。

8. Constraints

</>Markdown


## Constraints

- Do not modify the original Excel file.
- Do not delete records.
- Do not infer business meaning without evidence.
- Do not silently correct source data.
- Clearly distinguish facts from assumptions.

这个非常容易被忽略。它解决:Agent 什么不能做?

如果没有 Constraints,Agent 可能:发现拼写错误

直接修改

保存文件

但是 Skill 可以规定:”Do not modify the original file.”

于是:

Original file

Read only

Analyze

Report problems

这就是 Skill 的行为边界

9. Resources

假设我们还有一个 Python 工具:scripts/profile_excel.py

</> Markdown

## Resources

Use the following resources when needed:

- `scripts/profile_excel.py`
  - Use this script to profile Excel files.

- `references/data-quality-rules.md`
  - Contains standard data quality rules.

这时候 Skill 就不只是“文字”。Agent Skill 往往是一个目录(folder)

excel-skill/

├── SKILL.md

├── scripts/
│ └── profile_excel.py

├── references/
│ └── data-quality-rules.md

└── resources/
├── customer_schema.json
└── template.sql

SKILL.md 中对应的内容就是前面研究讨论的内容:

SKILL.md

├── Frontmatter
│ ├── name
│ └── description

├── Purpose (→ 这个 Skill 是干什么的)

├── When to Use (→ 什么情况下使用)

├── Capabilities (→ 它能做什么)

├── Instructions (→ Agent 应该怎么做)

├── Scripts (→ 可以调用哪些脚本)

├── References (→ 可以查哪些参考资料)

├── Resources (→ 可以使用哪些资源)

├── Output Format (→ 最终结果应该长什么样)

└── Examples (→ 给 Agent 看具体使用例子)

两层合起来

excel-skill/
│
├── SKILL.md
│   │
|   ├── Frontmatter
│       ├── name
│       └── description
|   |
│   ├── Purpose
│   ├── When to Use
│   ├── Capabilities
│   ├── Instructions
│   │
│   ├── Scripts
│   │      └──→ scripts/profile_excel.py
│   │
│   ├── References
│   │      └──→ references/data-quality-rules.md
│   │
│   ├── Resources
│   │      ├──→ resources/customer_schema.json
│   │      └──→ resources/template.sql
│   │
│   ├── Output Format
│   │
│   └── Examples
│
├── scripts/
│   └── profile_excel.py
│
├── references/
│   └── data-quality-rules.md
│
└── resources/
    ├── customer_schema.json
    └── template.sql

10. Output Format

接下来告诉 Agent:最终结果应该长什么样?e.g.

## Output Format

Return the analysis using the following structure:

### Executive Summary

Briefly summarize the overall data quality.

### Findings

| Issue | Severity | Affected Records | Recommendation |
|---|---|---:|---|

### Details

Explain each significant issue.

### Recommendations

Provide recommended next steps.

11. Examples

## Examples

### Example 1

User:

"Analyze customers.xlsx and find data quality issues."

Expected behavior:

1. Inspect workbook
2. Profile columns
3. Check missing values
4. Check duplicates
5. Check inconsistent values
6. Produce a structured report

A Complete SKILL.md Example

---
name: excel-data-analysis
description: Analyze Excel files, identify data quality issues, and produce structured findings and recommendations.
---

# Excel Data Analysis

## Purpose

This skill provides a structured workflow for analyzing Excel
workbooks, identifying data quality issues, and producing
business-oriented findings.

## When to Use

Use this skill when the user asks to:

- Analyze an Excel workbook
- Profile columns and data types
- Detect missing values
- Detect duplicate records
- Identify inconsistent values
- Produce data quality findings

Do not use this skill for:

- Creating presentations
- General spreadsheet formatting
- Writing Excel formulas without data analysis

## Capabilities

This skill can:

1. Inspect workbook structure
2. Profile columns
3. Detect missing values
4. Detect duplicate records
5. Detect inconsistent values
6. Generate a data quality summary

## Instructions

### Step 1: Inspect the workbook

Identify:

- Workbook name
- Sheet names
- Number of rows
- Number of columns
- Column names

### Step 2: Profile the data

For each column:

- Determine data type
- Calculate null count
- Calculate distinct count
- Identify suspicious values

### Step 3: Check data quality

Check for:

- Missing values
- Duplicate records
- Invalid formats
- Inconsistent categorical values

### Step 4: Analyze findings

Rank issues based on:

1. Severity
2. Business impact
3. Number of affected records

### Step 5: Produce the report

Generate the output using the required format.

## Constraints

- Do not modify the original Excel file.
- Do not delete records.
- Do not silently correct source data.
- Do not infer business meaning without evidence.
- Clearly distinguish facts from assumptions.

## Resources

Use the following resources when needed:

- `scripts/profile_excel.py`
  - Use this script to profile Excel files.

- `references/data-quality-rules.md`
  - Contains standard data quality rules.

## Output Format

### Executive Summary

Provide a concise summary of the overall data quality.

### Findings

| Issue | Severity | Affected Records | Recommendation |
|---|---|---:|---|

### Details

Explain significant findings and provide supporting evidence.

### Recommendations

Provide practical next steps.

## Examples

### Example 1

User:

"Analyze customers.xlsx and identify data quality issues."

Expected behavior:

1. Inspect the workbook.
2. Profile the columns.
3. Check missing values.
4. Check duplicates.
5. Check inconsistent values.
6. Rank the findings.
7. Produce the structured report.