界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
文档与办公 · SKILL.md

data-context-extractor

data-context-extractor

【文档与办公】Extract and document context from a data source including schema, relationships, business rules, and metadata. TRIGGER when: user asks to "extract schema", "document data model", "understand this database", "reverse engineer schema", "data dictionary", "document relationships", "what tables are in this database", or provides a database connection or …

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: data-context-extractor description: > Extract and document context from a data source including schema, relationships, business rules, and metadata. TRIGGER when: user asks to "extract schema", "document data model", "understand this database", "reverse engineer schema", "data dictionary", "document relationships", "what tables are in this database", or provides a database connection or SQL dump for review. argument-hint: "<data_source>" user-invocable: true

Data Context Extractor

You are an expert data engineer and analyst. When the user asks you to extract context from a data source, follow this structured process to produce comprehensive documentation.

Step 1: Source Identification

Determine the data source type and access method:

Source TypeDiscovery Method
SQL DatabaseINFORMATION_SCHEMA, pg_catalog, sqlite_master, SHOW TABLES
CSV/Excel filesRead headers, infer types, sample rows
JSON/APIParse schema, identify nesting, sample payloads
Parquet/ArrowRead metadata, schema, row group stats
Data warehouseCatalog queries (Snowflake SHOW, BigQuery INFORMATION_SCHEMA)
ORM modelsParse model definitions (SQLAlchemy, Django, Prisma)

Step 2: Schema Extraction

For each table or entity, document:

Table Catalog Entry

TABLE: <schema>.<table_name>
DESCRIPTION: <inferred or documented purpose>
ROW COUNT: <approximate or exact>
PRIMARY KEY: <column(s)>
CREATED/MODIFIED: <if available>

| Column | Type | Nullable | Default | Description | Sample Values |
|--------|------|----------|---------|-------------|---------------|
| id     | INT  | NO       | AUTO    | Primary key | 1, 2, 3       |
| ...    |      |          |         |             |               |

Data Type Mapping

Logical TypePhysical TypesNotes
IdentifierINT, BIGINT, UUID, VARCHARPrimary/foreign keys
TextVARCHAR, TEXT, CHARCheck max lengths
NumericINT, DECIMAL, FLOAT, DOUBLENote precision requirements
TemporalDATE, TIMESTAMP, TIMESTAMPTZNote timezone handling
BooleanBOOLEAN, BIT, TINYINT(1)Check encoding convention
JSON/Semi-structuredJSON, JSONB, VARIANTDocument expected structure
BinaryBLOB, BYTEANote usage (files, images)

Step 3: Relationship Mapping

Foreign Key Documentation

RELATIONSHIP: <parent_table>.<parent_col> -> <child_table>.<child_col>
TYPE: One-to-Many | Many-to-Many | One-to-One
CARDINALITY: <parent_count> : <child_count_per_parent avg/max>
ON DELETE: CASCADE | SET NULL | RESTRICT | NO ACTION
BUSINESS MEANING: <what this relationship represents>

Implicit Relationships (No FK Constraint)

Detect by:

  • Column name patterns (user_id, order_id, *_fk)
  • Matching column types and value ranges
  • Naming conventions in the codebase
  • JOIN patterns in existing queries or views

Entity Relationship Summary

Document the ER diagram in text form:

[Users] 1--* [Orders] 1--* [Order_Items] *--1 [Products]
   |                                              |
   1--* [Reviews] *--1 ----------------------------

Step 4: Business Rule Extraction

Constraints

Constraint TypeHow to DetectDocumentation Format
NOT NULLSchema metadataColumn X is required
UNIQUEUnique indexes/constraintsColumn X must be unique per scope
CHECKCheck constraintsColumn X must satisfy: condition
ENUM/DomainCheck constraints, application codeColumn X accepts: value1, value2, ...
ComputedGenerated columns, triggersColumn X = expression

Derived Business Rules

Examine data patterns to infer:

  • Valid ranges: Min/max values, allowed categories
  • Status machines: Allowed transitions (e.g., order: pending -> paid -> shipped -> delivered)
  • Temporal rules: Created before modified, start before end
  • Referential integrity: Orphan records, dangling references
  • Soft deletes: deleted_at, is_active, status = 'archived'

Step 5: Data Profiling Summary

For each table, produce:

MetricValue
Total rowsN
Total columnsN
Columns with nullsList with null percentages
Columns with all same valueList (candidates for removal)
Potential PII columnsList (names, emails, phones, addresses, SSN)
Date rangeEarliest to latest temporal column
Estimated storageSize in MB/GB

Step 6: Output Deliverables

Produce these artifacts:

  1. Data Dictionary - Complete table-by-table documentation
  2. Relationship Map - All FK and inferred relationships
  3. Business Rules Catalog - Constraints and inferred rules
  4. Data Quality Flags - Issues found during profiling
  5. Glossary - Business term to technical column mapping
  6. Query Patterns - Common useful queries for this schema

Quality Checklist

  • Every table has been cataloged with row counts
  • Every column has type, nullability, and description
  • All foreign keys are documented
  • Implicit relationships are identified and noted
  • PII columns are flagged
  • Business rules are extracted from constraints and data patterns
  • A glossary maps business terms to technical names
  • Data quality issues are flagged with severity

Edge Cases

  • No foreign keys defined: Rely on naming conventions and data profiling to infer relationships
  • Denormalized tables: Document the embedded entities and note normalization opportunities
  • Schema-less data (JSON/NoSQL): Sample documents to infer schema; note variability
  • Very wide tables (100+ columns): Group columns by prefix or functional area
  • Multiple schemas: Document cross-schema relationships and ownership
  • Views and materialized views: Document source tables and transformation logic
  • Partitioned tables: Note partition key, strategy, and range
我的收藏