Paths/MLOps Engineer/Data Quality & Labeling / Contracts & Checks
Write a Data Contract
A contract states the columns a table must have and the rules those columns must follow. Write the contract for the users table.
Validator
IDLE — checks run live as you type commands; submit when done
01Requirements
live checks- Directory ~/data/contracts exists○
- File ~/data/contracts/users.yaml exists○
- The contract declares the columns and their types○
- The contract states the expectations - no nulls and known country codes○
02Walkthrough
5 steps- 01
Create the contracts directory
Contracts belong next to the data they describe, in one reviewable place.
mkdir -p ~/data/contracts - 02
Declare the columns
name and type per column. The type is the contract - a string where a number belongs breaks every downstream aggregation.
echo 'name: users\ncolumns:\n - name: user_id\n type: int64\n - name: country\n type: string\n - name: created_at\n type: timestamp' > ~/data/contracts/users.yaml - 03
Declare the expectations
expectations are the checks the pipeline runs. not_null means the column can never be empty.
echo 'expectations:\n - name: user_id_not_null\n type: not_null\n column: user_id\n - name: country_known\n type: accepted_values\n column: country\n values: [DE, FR, NL, PL]' >> ~/data/contracts/users.yaml - 04
Verify the contract
cat prints the contract. Add an expectation for every bug the team has hit.
cat ~/data/contracts/users.yaml - 05
Submit for validation
The validator checks the columns, the expectations and both kinds of check.
03Stuck?
0 of 3 revealedTake a hint without losing the lab — each one points at the thing to look at, not at the answer.
04AI Tutor
guides, never solvesTell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?
04Notebook
saved locally in this browserlearner@lab — ubuntu:24.04
Session is disposable
↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list