OpenParable
Skip to content
← Back to skills

Schema Validator

Documents
schema_validator

Schema Validator is an Agent Skill for documents published in the cas-bigdatalab/piflow repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

显式 schema 校验工具。读取结构化数据与用户提供的 schema,检查字段存在性、字段类型、枚举、范围、长度、正则格式、日期格式、表级行数与缺失率约束,并输出校验报告。 当用户提到 schema 校验、结构校验、模式校验、字段存在性检查、字段类型检查、枚举校验、范围校验、格式校验、表头结构校验等需求时使用此 skill。 即使用户没有明确说出"schema_validator",只要任务是在检查结构化数据是否符合明确 schema 规则,就应该使用此 skill。 不负责数据清洗、去重、业务合理性判断、跨字段一致性、参照完整性、分布异常分析或数据转换。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/cas-bigdatalab/piflow/blob/HEAD/workspace/skills/schema_validator/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/schema-validator, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Schema Validator 显式 schema 校验 Skill

功能概述

本 skill 用于验证结构化数据是否符合用户提供的明确 schema 规则。它检查字段是否存在、类型是否匹配、枚举值是否合规、数值是否超出范围、字符串长度是否合规、正则格式是否匹配、日期格式是否正确,以及嵌套对象/数组结构是否符合定义。它还支持表级约束,例如最小行数、最大缺失率、字段顺序与额外字段控制。

触发条件

当用户请求以下任务时,应使用此 skill:

  • schema 校验
  • 结构校验
  • 模式校验
  • 字段存在性检查
  • 字段类型检查
  • 枚举校验
  • 范围校验
  • 格式校验
  • 表头结构校验

schema 定义格式

{
  "fields": {
    "id": {
      "type": "int",
      "required": true,
      "nullable": false
    },
    "name": {
      "type": "str",
      "required": true,
      "min_length": 1,
      "max_length": 100
    },
    "status": {
      "type": "str",
      "enum": ["active", "inactive", "pending"]
    },
    "score": {
      "type": "float",
      "min": 0,
      "max": 100
    },
    "email": {
      "type": "str",
      "pattern": "^[\\w.-]+@[\\w.-]+\\.\\w+$"
    },
    "created_at": {
      "type": "date",
      "format": "%Y-%m-%d"
    }
  },
  "table_constraints": {
    "min_rows": 10,
    "max_missing_ratio": 0.2,
    "strict_columns": true,
    "check_column_order": true
  }
}

支持的验证规则

规则说明适用类型
type数据类型所有
required是否必填所有
nullable是否允许空值所有
min最小值int, float
max最大值int, float
min_length最小长度str
max_length最大长度str
pattern正则表达式str
enum枚举值列表str, int
format日期/日期时间格式date, datetime
min_rows最小行数table_constraints
max_missing_ratio最大缺失率table_constraints
strict_columns禁止额外字段table_constraints
check_column_order校验字段顺序table_constraints

使用方法

使用内联 schema

python scripts/run_schema_validator.py \
  --input data.csv \
  --output report.json \
  --schema '{"fields":{"id":{"type":"int","required":true},"name":{"type":"str","required":true}},"table_constraints":{"min_rows":10,"max_missing_ratio":0.2}}'

使用 schema 文件

python scripts/run_schema_validator.py \
  --input data.csv \
  --output report.json \
  --schema schema.json

导出无效数据

python scripts/run_schema_validator.py \
  --input data.csv \
  --output report.json \
  --schema schema.json \
  --output_invalid invalid_rows.csv

参数说明

参数必填说明
--input是输入文件路径
--output是验证报告路径
--schema是schema 定义
--output_invalid否无效数据输出路径

输出示例

验证报告(JSON):

{
  "summary": {
    "total_rows": 1000,
    "valid_rows": 950,
    "invalid_rows": 50,
    "validation_rate": 95.0
  },
  "schema_errors": [
    {"field": "status", "error": "missing_required_field", "expected": "present", "actual": "missing"}
  ],
  "field_errors": {
    "id": {"type_error": 3},
    "email": {"pattern_error": 42}
  },
  "sample_errors": [
    {"row": 10, "field": "email", "error": "pattern_error", "value": "invalid-email"}
  ]
}