Skill: Semantic Schema Mapping Planning
Follow this structured process and procedures for analyzing source-to-target
data relationships and creating a high-fidelity Mapping Plan (also known as
a Mapping Manifesto). This process is platform-agnostic and should be used
before generating any target-specific pipeline code. When this skill is loaded,
you MUST use this plan and replace the existing generic plan.
When to Use
Use this skill when:
- You need to map schemas between a source dataset/database and a target
destination database/warehouse.
- You are initiating an ETL, ELT, or data integration task.
- You need to identify schema gaps, data type conflicts, or aggregation
requirements.
Required Input Variables
Before creating the plan, you must obtain or request:
SOURCE_SCHEMAS: Definitions (schemas, tables, fields, types) of the
source data.
TARGET_SCHEMAS: Definitions of the desired target/destination schemas.
BUSINESS_CONTEXT: Domain details, business rules, or use case
description.
TARGET_PLATFORM: The database or execution engine (e.g., BigQuery,
Snowflake, Postgres, Spark, Beam).
Optional Input Variables
KNOWLEDGE_GRAPH: If there's a knowledge graph / property graph
available, always inspect the graph for node table definitions, edge table
definitions, and foreign key bindings (SOURCE / DESTINATION key
references), etc.
The Schema Mapping Planning Procedure
[!IMPORTANT] Execution Strategy: Table-by-Table Iteration
You MUST execute this procedure iteratively, one target table at a time.
For each individual table in the TARGET_SCHEMAS, complete Steps 1 through 6
sequentially before moving to the next table. Do not attempt to map or
summarize multiple tables in a single batch, as this leads to hallucinations,
overlooked constraints, and context window bloat.
Step 1: Semantic & Terminology Translation
Analyze the entity names and attributes in the SOURCE_SCHEMAS against the
TARGET_SCHEMAS.
- Synonym Resolution: Using the
BUSINESS_CONTEXT, map matching concepts
with different names (e.g., client_id vs customer_num).
- Identify Domain Standards: Match field values or formats to known
standards (e.g., ISO country codes, currency codes, UN/LOCODE, UUIDs) based
on the business context.
- Verify Domain Semantics: Do not rely purely on lexical matching (name
similarity). Verify the functional business purpose of the entities in both
schemas. Ensure that a target table representing a specific business
resource maps to a source table modeling that same resource rather than an
unrelated administrative log or generic list table sharing a similar name.
Step 2: Establish the Anchor Table
For each table or collection in the TARGET_SCHEMAS:
- Identify the primary source table (the "Anchor Table") that holds the
core records for this target.
- Identify contributing/lookup tables in the source that will enrich the
target records.
- Prefer Structured Tables over Generic Key-Value Tables: If the same
attribute exists in both a structured column in a domain table and as a
generic property in an Entity-Attribute-Value (EAV) key-value/properties
table, always anchor on the structured table to ensure schema stability and
performant joins.
Step 3: Proactive Data Sampling & Inspection
If a target field mapping is ambiguous or schema types do not tell the whole
story (e.g., verifying if a timestamp is ISO-8601, if a string is a JSON array,
or checking the distribution of values):
- Proactive Inspection: If environment access allows, run
platform-specific queries (e.g.,
SELECT ... LIMIT 10, SELECT COUNT(DISTINCT ... )) to sample values.
- User Inquiry: If direct access is not possible, output sample queries
and ask the user to provide the output to confirm assumptions before
finalizing the plan.
Step 4: Perform Field-Level Gap Analysis & Cleanliness Design
Evaluate every column in each target table to determine its source mapping.
Categorize mappings and plan cleanliness transformations:
- Direct Mapping: A 1-to-1 match.
- Derived Mapping: Requires type casting, string manipulation, date
formatting, mathematical derivation, or case statement logic.
- Joined Mapping: Requires looking up values from contributing tables
using defined join keys.
- Aggregated Mapping: Requires collapsing 1-to-many relationships (e.g.,
calculating
SUM, COUNT, ARRAY_AGG or string concatenation).
- Gaps (Unmapped fields): Target fields that do not exist in the source.
- Constraint Checking: Verify whether the target column has a
NOT NULL or REQUIRED constraint in the target schema.
- Handling Nullable Gaps: If the target column is nullable, explicitly
flag it as
NULL or define a default value.
- Handling Non-Nullable Gaps: If the target column is
NOT NULL, you
MUST NOT map it to NULL. (Rationale: Mapping NOT NULL target columns
to NULL will cause execution-time database constraint violations and
pipeline failures). You must identify a source field to derive it from,
default it to a valid non-null placeholder (e.g., 'UNKNOWN', 0, or
default dates), or define logic to generate a valid unique reference.
Universal Data Cleanliness Rules to Incorporate in Mappings:
- Null Standardization: Map source strings like
"NULL", "None",
"N/A", or empty spaces to true database NULL values.
- Trim & Casing: Plan to trim leading/trailing whitespaces. Convert
standardized codes (e.g., ISO codes, status strings) to uppercase.
- Temporal Consistency: Plan to parse all source timestamps into standard
ISO-8601 format (
YYYY-MM-DDTHH:MM:SSZ) or standard destination TIMESTAMP
format. Plan checks to ensure logical temporal progression (e.g.,
start_time <= end_time).
- Defensive Checks: Plan checks for strict destination types (e.g.,
checking if string is a valid number before casting to
DECIMAL).
Step 5: Map Relationships & Joins
Specify the logical join path to connect the Anchor Table with all contributing
source tables:
- Define the join condition/keys (e.g.,
source_order.customer_id = source_customer.id).
- Identify join scale properties:
- Large-to-Large: Joining two high-volume transaction tables.
- Large-to-Small: Joining a transaction table to a static lookup table
(ideal for Map-side/Broadcast joins to optimize speed/cost).
- Document potential join challenges:
- Many-to-many risks or potential duplicate generation.
- Type mismatches on join keys (e.g., joining an
INT column to a
STRING column).
- Graph Validation: If a graph was identified in input, cross-reference
the proposed join conditions with the graph's edge table definitions to
validate foreign key relationships.
Step 6: Draft the "Mapping Manifesto" (Output Format & Example)
Analyze the schemas and reference the ONE_SHOT_EXAMPLE below to structure your
output.
ONE_SHOT_EXAMPLE (How to Structure the Mapping Manifesto)
Example Source Schemas
dataset: my_music_library
style: {id: int, style: string}
band: {name: string, biography: string, style: int}
cd: {name: string, year: int, artist: string, numbers: array<string>}
track: {id: string, number: int, name: string}
Example Target Schemas
dataset: music_standard
artist: {name: string, albums: array<string>}
album: {name: string, year: int, genre: string, tracks: array<string>}
The Mapping Manifesto (Expected Output Format)
For each target table, document your column-to-column reasoning:
# Mapping Plan: `album`
* **Anchor Source Table**: `cd`
* **Join Paths & Optimization**:
* `cd` JOIN `band` ON `cd.artist = band.name`
* `band` JOIN `style` ON `band.style = style.id`
* `cd` JOIN `track` ON `track.id IN UNNEST(cd.numbers)`
### Field Mappings
| Target Field | Source Field / Logic | Mapping Type | Rationale / Transformation Details |
| :--- | :--- | :--- | :--- |
| `album.name` | `cd.name` | Direct | A CD is a physical medium representing an album; direct semantic match |
| `album.year` | `cd.year` | Direct | Direct semantic match for release year |
| `album.genre` | `style.style` | Joined | Resolved via `cd.artist` -> `band.name` -> `band.style` (ID) -> `style.id` -> `style.style` (String) |
| `album.tracks` | `ARRAY_AGG(track.name)` | Aggregated | Aggregation Point: Collapses 1-to-many track IDs in `cd.numbers` into an array of track names |
Critical Operational Rules
- Plan Before Execution: You MUST NOT generate any ETL code,
target-specific pipeline configurations, or migration scripts until the
Mapping Manifesto has been presented to and approved by the user.
(Rationale: Establishing clear mapping logic first prevents coding errors,
avoids circular dependencies, and ensures user alignment on semantic
mappings before wasting resources on implementation).
- Strict Schema Grounding: Every source table and field name referenced in
the mapping plan MUST exactly match the names and data types present in the
provided
SOURCE_SCHEMAS. You MUST NOT reference non-existent columns,
guess field names, or make assumptions about source schemas without
explicitly confirming them in the schema definitions. (Rationale: Proposing
guesses leads to compilation errors and invalid mapping specifications).
- Target Schema Constraint Integrity: You must never propose a mapping
that writes
NULL to a column defined as NOT NULL or REQUIRED in the
TARGET_SCHEMAS.
- Exhaustive Field Search: Before declaring a target field as an "Unmapped
/ Gap", search all available source schemas to verify the data is not in a
less-obvious table. (Rationale: Lazy mappings that default target fields to
NULL lead to downstream data loss and incomplete pipelines).
- Defensive Type Mapping: Explicitly plan the transformation rules for
strict destination types (e.g.
TIMESTAMP, BOOLEAN, DECIMAL) to avoid
load failures. (Rationale: Different databases and platforms handle type
validation strictly; pre-planning casts prevents execution-time runtime
errors).
- Data Integrity Check: Identify join conditions that could cause
Cartesian product expansion or data duplication, and note prevention
strategies in the plan. (Rationale: Unvalidated joins can distort
aggregated metrics or exhaust processing memory on large datasets).
1---2name: schema-mapping3description: Guides the process of analyzing, mapping, and documenting transformations between source and target schemas for any database, data warehouse, or data platform. Focuses exclusively on creating a high-fidelity mapping plan (Mapping Manifesto). Used when initiating an ETL, ELT, or data integration task with schema mapping specification for multiple tables (i.e. more than 3 tables) before writing code. Do NOT use this skill for basic SQL generation without mapping requirements, or when the user already has a complete mapping specification.4license: Apache-2.05---67# Skill: Semantic Schema Mapping Planning89Follow this structured process and procedures for analyzing source-to-target10data relationships and creating a high-fidelity **Mapping Plan** (also known as11a **Mapping Manifesto**). This process is platform-agnostic and should be used12before generating any target-specific pipeline code. When this skill is loaded,13you MUST use this plan and replace the existing generic plan.1415## When to Use1617Use this skill when:1819- You need to map schemas between a source dataset/database and a target20 destination database/warehouse.21- You are initiating an ETL, ELT, or data integration task.22- You need to identify schema gaps, data type conflicts, or aggregation23 requirements.2425--------------------------------------------------------------------------------2627## Required Input Variables2829Before creating the plan, you must obtain or request:30311. **`SOURCE_SCHEMAS`**: Definitions (schemas, tables, fields, types) of the32 source data.332. **`TARGET_SCHEMAS`**: Definitions of the desired target/destination schemas.343. **`BUSINESS_CONTEXT`**: Domain details, business rules, or use case35 description.364. **`TARGET_PLATFORM`**: The database or execution engine (e.g., BigQuery,37 Snowflake, Postgres, Spark, Beam).3839## Optional Input Variables40411. **`KNOWLEDGE_GRAPH`**: If there's a knowledge graph / property graph42 available, always inspect the graph for node table definitions, edge table43 definitions, and foreign key bindings (`SOURCE` / `DESTINATION` key44 references), etc.4546--------------------------------------------------------------------------------4748## The Schema Mapping Planning Procedure4950> [!IMPORTANT] **Execution Strategy: Table-by-Table Iteration**51>52> You MUST execute this procedure **iteratively, one target table at a time**.53> For each individual table in the `TARGET_SCHEMAS`, complete Steps 1 through 654> sequentially before moving to the next table. Do not attempt to map or55> summarize multiple tables in a single batch, as this leads to hallucinations,56> overlooked constraints, and context window bloat.5758### Step 1: Semantic & Terminology Translation5960Analyze the entity names and attributes in the `SOURCE_SCHEMAS` against the61`TARGET_SCHEMAS`.62631. **Synonym Resolution**: Using the `BUSINESS_CONTEXT`, map matching concepts64 with different names (e.g., `client_id` vs `customer_num`).652. **Identify Domain Standards**: Match field values or formats to known66 standards (e.g., ISO country codes, currency codes, UN/LOCODE, UUIDs) based67 on the business context.683. **Verify Domain Semantics**: Do not rely purely on lexical matching (name69 similarity). Verify the functional business purpose of the entities in both70 schemas. Ensure that a target table representing a specific business71 resource maps to a source table modeling that same resource rather than an72 unrelated administrative log or generic list table sharing a similar name.7374### Step 2: Establish the Anchor Table7576For each table or collection in the `TARGET_SCHEMAS`:77781. Identify the **primary source table** (the "Anchor Table") that holds the79 core records for this target.802. Identify **contributing/lookup tables** in the source that will enrich the81 target records.823. **Prefer Structured Tables over Generic Key-Value Tables**: If the same83 attribute exists in both a structured column in a domain table and as a84 generic property in an Entity-Attribute-Value (EAV) key-value/properties85 table, always anchor on the structured table to ensure schema stability and86 performant joins.8788### Step 3: Proactive Data Sampling & Inspection8990If a target field mapping is ambiguous or schema types do not tell the whole91story (e.g., verifying if a timestamp is ISO-8601, if a string is a JSON array,92or checking the distribution of values):93941. **Proactive Inspection**: If environment access allows, run95 platform-specific queries (e.g., `SELECT ... LIMIT 10`, `SELECT96 COUNT(DISTINCT ... )`) to sample values.972. **User Inquiry**: If direct access is not possible, output sample queries98 and ask the user to provide the output to confirm assumptions before99 finalizing the plan.100101### Step 4: Perform Field-Level Gap Analysis & Cleanliness Design102103Evaluate every column in each target table to determine its source mapping.104Categorize mappings and plan cleanliness transformations:105106* **Direct Mapping**: A 1-to-1 match.107* **Derived Mapping**: Requires type casting, string manipulation, date108 formatting, mathematical derivation, or case statement logic.109* **Joined Mapping**: Requires looking up values from contributing tables110 using defined join keys.111* **Aggregated Mapping**: Requires collapsing 1-to-many relationships (e.g.,112 calculating `SUM`, `COUNT`, `ARRAY_AGG` or string concatenation).113* **Gaps (Unmapped fields)**: Target fields that do not exist in the source.114 * **Constraint Checking**: Verify whether the target column has a `NOT115 NULL` or `REQUIRED` constraint in the target schema.116 * **Handling Nullable Gaps**: If the target column is nullable, explicitly117 flag it as `NULL` or define a default value.118 * **Handling Non-Nullable Gaps**: If the target column is `NOT NULL`, you119 MUST NOT map it to `NULL`. *(Rationale: Mapping NOT NULL target columns120 to NULL will cause execution-time database constraint violations and121 pipeline failures).* You must identify a source field to derive it from,122 default it to a valid non-null placeholder (e.g., `'UNKNOWN'`, `0`, or123 default dates), or define logic to generate a valid unique reference.124125#### Universal Data Cleanliness Rules to Incorporate in Mappings:1261271. **Null Standardization**: Map source strings like `"NULL"`, `"None"`,128 `"N/A"`, or empty spaces to true database `NULL` values.1292. **Trim & Casing**: Plan to trim leading/trailing whitespaces. Convert130 standardized codes (e.g., ISO codes, status strings) to uppercase.1313. **Temporal Consistency**: Plan to parse all source timestamps into standard132 ISO-8601 format (`YYYY-MM-DDTHH:MM:SSZ`) or standard destination `TIMESTAMP`133 format. Plan checks to ensure logical temporal progression (e.g.,134 `start_time <= end_time`).1354. **Defensive Checks**: Plan checks for strict destination types (e.g.,136 checking if string is a valid number before casting to `DECIMAL`).137138### Step 5: Map Relationships & Joins139140Specify the logical join path to connect the Anchor Table with all contributing141source tables:1421431. Define the join condition/keys (e.g., `source_order.customer_id =144 source_customer.id`).1452. Identify join scale properties:146 - **Large-to-Large**: Joining two high-volume transaction tables.147 - **Large-to-Small**: Joining a transaction table to a static lookup table148 (ideal for Map-side/Broadcast joins to optimize speed/cost).1493. Document potential join challenges:150 - Many-to-many risks or potential duplicate generation.151 - Type mismatches on join keys (e.g., joining an `INT` column to a152 `STRING` column).1534. **Graph Validation**: If a graph was identified in input, cross-reference154 the proposed join conditions with the graph's edge table definitions to155 validate foreign key relationships.156157### Step 6: Draft the "Mapping Manifesto" (Output Format & Example)158159Analyze the schemas and reference the `ONE_SHOT_EXAMPLE` below to structure your160output.161162#### ONE_SHOT_EXAMPLE (How to Structure the Mapping Manifesto)163164##### Example Source Schemas165166```markdown167dataset: my_music_library168style: {id: int, style: string}169band: {name: string, biography: string, style: int}170cd: {name: string, year: int, artist: string, numbers: array<string>}171track: {id: string, number: int, name: string}172```173174##### Example Target Schemas175176```markdown177dataset: music_standard178artist: {name: string, albums: array<string>}179album: {name: string, year: int, genre: string, tracks: array<string>}180```181182##### The Mapping Manifesto (Expected Output Format)183184For each target table, document your column-to-column reasoning:185186```markdown187# Mapping Plan: `album`188* **Anchor Source Table**: `cd`189* **Join Paths & Optimization**:190 * `cd` JOIN `band` ON `cd.artist = band.name`191 * `band` JOIN `style` ON `band.style = style.id`192 * `cd` JOIN `track` ON `track.id IN UNNEST(cd.numbers)`193194### Field Mappings195196| Target Field | Source Field / Logic | Mapping Type | Rationale / Transformation Details |197| :--- | :--- | :--- | :--- |198| `album.name` | `cd.name` | Direct | A CD is a physical medium representing an album; direct semantic match |199| `album.year` | `cd.year` | Direct | Direct semantic match for release year |200| `album.genre` | `style.style` | Joined | Resolved via `cd.artist` -> `band.name` -> `band.style` (ID) -> `style.id` -> `style.style` (String) |201| `album.tracks` | `ARRAY_AGG(track.name)` | Aggregated | Aggregation Point: Collapses 1-to-many track IDs in `cd.numbers` into an array of track names |202```203204--------------------------------------------------------------------------------205206## Critical Operational Rules207208* **Plan Before Execution**: You MUST NOT generate any ETL code,209 target-specific pipeline configurations, or migration scripts until the210 Mapping Manifesto has been presented to and approved by the user.211 *(Rationale: Establishing clear mapping logic first prevents coding errors,212 avoids circular dependencies, and ensures user alignment on semantic213 mappings before wasting resources on implementation).*214* **Strict Schema Grounding**: Every source table and field name referenced in215 the mapping plan MUST exactly match the names and data types present in the216 provided `SOURCE_SCHEMAS`. You MUST NOT reference non-existent columns,217 guess field names, or make assumptions about source schemas without218 explicitly confirming them in the schema definitions. *(Rationale: Proposing219 guesses leads to compilation errors and invalid mapping specifications).*220* **Target Schema Constraint Integrity**: You must never propose a mapping221 that writes `NULL` to a column defined as `NOT NULL` or `REQUIRED` in the222 `TARGET_SCHEMAS`.223* **Exhaustive Field Search**: Before declaring a target field as an "Unmapped224 / Gap", search all available source schemas to verify the data is not in a225 less-obvious table. *(Rationale: Lazy mappings that default target fields to226 NULL lead to downstream data loss and incomplete pipelines).*227* **Defensive Type Mapping**: Explicitly plan the transformation rules for228 strict destination types (e.g. `TIMESTAMP`, `BOOLEAN`, `DECIMAL`) to avoid229 load failures. *(Rationale: Different databases and platforms handle type230 validation strictly; pre-planning casts prevents execution-time runtime231 errors).*232* **Data Integrity Check**: Identify join conditions that could cause233 Cartesian product expansion or data duplication, and note prevention234 strategies in the plan. *(Rationale: Unvalidated joins can distort235 aggregated metrics or exhaust processing memory on large datasets).*