data-contracts

Validates data transforms, joins, and aggregations with contracts and invariants in R, Julia, Python, and Stata.

2|Updated Jun 8, 2026
One-click install
npx skills add https://github.com/lancegui/causal-powers --skill data-contracts-lancegui
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: data-contracts
Source: https://github.com/lancegui/causal-powers/tree/main/evals/prompt-pilot-state-did/transcripts/current/stage1/instructions/skills/data-contracts
Command: npx skills add https://github.com/lancegui/causal-powers --skill data-contracts-lancegui

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Data analysis failures are silent: joins fan out, NAs poison means, and units drift without any error, producing confident but wrong numbers. This Skill establishes data contracts and invariants before computing, so bad assumptions are caught before they reach a reported result. ## Core Features & Use Cases - Merge protocol: Declares and enforces join cardinality (1:1, 1:m, m:1), tabulates match rates and NA counts in merged-in columns, and reconciles totals back to the source after every join. - NA map and invariant catalog: Tabulates per-column missingness at first load and asserts keys, ranges, categories, units, temporal sanity, and leakage before trusting any output. - Golden baselines: Freezes validated results as committed reference outputs so future re-runs and refactors diff against them like regression tests. - Use Case: Before merging a panel dataset with a customer table in pandas, declare a many-to-one relationship, assert the row count is preserved, tabulate unmatched keys, and reconcile revenue totals — catching a silent fan-out before it corrupts the regression sample. ## Quick Start Use the data-contracts skill to validate this dataset load and the upcoming merge before I compute any summary statistics.

Frequently Asked Questions about data-contracts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate a pandas merge to prevent silent row fan-out?▼

Use the validate argument in pandas merge, such as validate="one_to_one" or "many_to_one", to enforce declared cardinality. Then assert the output row count matches the left side and tabulate NA counts in the merged-in columns to catch unmatched keys.

How to check join cardinality in R dplyr?▼

Pass the relationship argument to dplyr joins, for example left_join(x, y, by="id", relationship="many-to-one"), which errors on violations. Combine with anti_join to inspect unmatched keys and stopifnot to bracket row counts around the merge.

Does this validation approach work with Stata datasets?▼

Yes, Stata ships contract primitives natively: isid checks key uniqueness, merge with assert() enforces match cardinality, and datasignature freezes and verifies dataset state. The reference helpers include a full Stata prelude alongside Python, R, and Julia.

Why does my analysis give wrong numbers without any errors?▼

Silent failures like join fan-outs, NA-poisoned aggregations, unit mismatches, and vintage-mismatched keys run cleanly while corrupting results. Asserting invariants such as row counts, totals reconciliation, and missingness maps at each pipeline boundary exposes these failures before they reach a reported figure.

When should I not add more validation checks to a pipeline?▼

Avoid check inventories: each check must name a specific silent failure it catches, with one check per failure mode placed at ingest, merges, sample construction, and report time. A single-join script needs roughly four checks; redundant asserts and standalone check directories add ceremony without rigor.