Learn Everything

Paths/MLOps Engineer/Data Quality & Labeling / Contracts & Checks

Guided Taskbeginnerubuntu:24.04Ask AI

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

⏱ 0:00

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
  1. 01

    Create the contracts directory

    Contracts belong next to the data they describe, in one reviewable place.

    mkdir -p ~/data/contracts
  2. 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
  3. 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
  4. 04

    Verify the contract

    cat prints the contract. Add an expectation for every bug the team has hit.

    cat ~/data/contracts/users.yaml
  5. 05

    Submit for validation

    The validator checks the columns, the expectations and both kinds of check.

03Stuck?

0 of 3 revealed

Take a hint without losing the lab — each one points at the thing to look at, not at the answer.

04AI Tutor

guides, never solves

Tell me what you're stuck on — I'll nudge, not solve. Which requirement are you looking at?

04Notebook

saved locally in this browser

learner@lab — ubuntu:24.04

↑/↓ recalls commands · Ctrl+Enter submits · type help for the command list