Importing Data Skill
Relevant source files
The following files were used as context for generating this wiki page:
The Importing Data Skill converts CSV and TSV data into Infrahub object YAML for loading onto a fresh branch. It acts as a bridge between spreadsheet-style inputs and Infrahub objects, handling single files, directories of files, or denormalized sheets that require splitting across multiple schema nodes.
Sources: skills/infrahub-importing-data/SKILL.md:16-20, AGENTS.md:144-145
Overview and Scope
The skill consumes the live Infrahub schema to validate and map incoming data. It operates under a "fail-closed" policy: if a CSV column cannot be mapped to an existing schema attribute, the process stops and requires a separate schema update via the Managing Schemas Skill.
Primary Functions
- Dialect Detection: Identifies delimiters, encoding, and line endings in CSV/TSV files.
- Schema Introspection: Reads the deployed schema via MCP, CLI, or REST to ensure mapping accuracy.
- Data Transformation: Handles value coercion for booleans, numbers, and dates; normalizes dropdown labels; and collapses interface-style ranges.
- Branch-First Loading: Ensures all data is loaded onto a reviewable branch rather than the default branch.
Sources: skills/infrahub-importing-data/SKILL.md:22-26, skills/infrahub-importing-data/SKILL.md:86-130
Data Import Architecture
The import process follows a structured 14-step workflow that prioritizes data integrity and schema compliance.
Workflow Sequence
The following diagram illustrates the sequence of operations from raw input to Infrahub branch loading.
The diagram shows the 14-step gating process where each step must pass before the next initiates.
Sources: skills/infrahub-importing-data/SKILL.md:105-180
Component Logic and Implementation
Schema Introspection Priority
To ensure the mapping is authoritative, the skill attempts to discover the schema using the following priority order:
- MCP Server: Sees the live deployed state, including branch-specific choices.
infrahubctl schema export: CLI-based export if MCP is disconnected.- REST Endpoint: Direct HTTP fetch from
/api/schema. - Local Files: Last resort using
schemas/*.ymlin the repository.
Sources: skills/infrahub-importing-data/SKILL.md:118-131, dev/knowledges/architecture.md:112-120
Mapping Heuristics
The skill applies several heuristics to automatically bind CSV columns to Infrahub attributes:
- Exact and Fuzzy Matching: Matches column names to attributes using snake_case and display-label logic.
- Value Coercion: Explicitly converts strings to Boolean, Number, DateTime, or JSON as required by the schema.
- Dropdown Translation: Translates human-readable labels into the internal
namevalues defined in the schema. - HFID Detection: Identifies reference columns by matching values against the target kind's Human Friendly ID (HFID).
Sources: skills/infrahub-importing-data/SKILL.md:135-152, dev/knowledges/infrahub-concepts.md:37-40
Schema Feature Dependencies
The skill's ability to emit valid YAML depends on specific features being configured within the target Infrahub schema.
| Input Feature | Schema Requirement | Citation |
|---|---|---|
| Reference Column | human_friendly_id must be defined on the target node. | SKILL.md:92-94 |
| Dropdown Label | Choices must be objects with both name and label. | SKILL.md:95-97 |
| Repeated Parent Rows | Component and Parent relationships must share an identifier. | SKILL.md:98-100 |
| Unmapped Column | Schema must be extended before import can proceed. | SKILL.md:101-103 |
Sources: skills/infrahub-importing-data/SKILL.md:90-104, skills/infrahub-managing-objects/SKILL.md:65-75
Output and Validation
Object YAML Format
The skill emits files to a local directory (default ./output_dir/). These files follow the standard Infrahub object envelope:
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: DcimDevice
data:
- name: spine-01
status: active
Sources: skills/infrahub-importing-data/SKILL.md:162-166, skills/infrahub-managing-objects/SKILL.md:90-97
File Organization
Files are organized to ensure correct loading order and provenance tracking:
- Numbering: Files use a
NN_<kind-plural>.ymlprefix to maintain dependency order. - Provenance: Each file includes a leading comment with the source CSV path, sha256 hash, and timestamp.
- Load Strategy: All loads occur on a dedicated branch (e.g.,
csv-import-YYYYMMDD). If a partial load fails, the branch is discarded rather than manually cleaned.
Sources: skills/infrahub-importing-data/SKILL.md:165-178, skills/infrahub-managing-objects/SKILL.md:105-110
Summary
The Importing Data Skill provides a rigorous, fail-closed workflow for ingesting spreadsheet data into Infrahub. By enforcing schema compliance and branch-first operations, it ensures that data imports are predictable, reviewable, and maintain the integrity of the infrastructure source of truth.
Sources: skills/infrahub-importing-data/SKILL.md:22-26, dev/knowledges/infrahub-concepts.md:94-96