Inventory Levels

Inventory Levels

Data Contract Template

Data Contract Template

Ensure Inventory Levels data is fresh, consistent, and reliable before its used for availability, replenishment, and fulfillment decisions.

Data contract description

This data contract enforces schema stability, a 24-hour freshness SLA, and required product/location identifiers and update timestamps. It prevents missing or invalid stock values, blocks negative inventory states, ensures reserved stock never exceeds on-hand stock, and enforces that available stock correctly reflects on-hand minus reserved. Together, these checks reduce overselling risk, prevent broken availability signals in ecommerce and stores, and protect replenishment, allocation, and fulfillment processes.

inventory_levels_data_contract.yml

dataset
variables:
  FRESHNESS_HOURS:
    default: 24

checks:
  - schema: {}
  - row_count:
      threshold:
        must_be_greater_than: 0
  - freshness:
      column: last_updated_at
      threshold:
        unit: hour
        must_be_less_than_or_equal: ${var.FRESHNESS_HOURS}
  - failed_rows:
      name: "Stock values must never be negative"
      qualifier: non_negative_stocks
      expression: >
        stock_on_hand < 0
        OR stock_reserved < 0
        OR stock_available < 0
  - failed_rows:
      name: "Reserved stock cannot exceed stock on hand"
      qualifier: reserved_le_on_hand
      expression: stock_reserved > stock_on_hand
  - failed_rows:
      name: "Available stock must equal on_hand minus reserved"
      qualifier: available_equals_on_hand_minus_reserved
      expression: stock_available <> (stock_on_hand - stock_reserved)
  - failed_rows:
      name: "last_updated_at must not be in the future"
      qualifier: last_updated_not_future
      expression

columns:
  - name: product_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: location_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: stock_on_hand
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Stock on hand must be zero or positive"
          valid_min: 0
  - name: stock_reserved
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Reserved stock must be zero or positive"
          valid_min: 0
  - name: stock_available
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Available stock must be zero or positive"
          valid_min: 0
  - name: last_updated_at
    data_type: dateTime
    checks:
      - missing

Data contract description

This data contract enforces schema stability, a 24-hour freshness SLA, and required product/location identifiers and update timestamps. It prevents missing or invalid stock values, blocks negative inventory states, ensures reserved stock never exceeds on-hand stock, and enforces that available stock correctly reflects on-hand minus reserved. Together, these checks reduce overselling risk, prevent broken availability signals in ecommerce and stores, and protect replenishment, allocation, and fulfillment processes.

inventory_levels_data_contract.yml

dataset
variables:
  FRESHNESS_HOURS:
    default: 24

checks:
  - schema: {}
  - row_count:
      threshold:
        must_be_greater_than: 0
  - freshness:
      column: last_updated_at
      threshold:
        unit: hour
        must_be_less_than_or_equal: ${var.FRESHNESS_HOURS}
  - failed_rows:
      name: "Stock values must never be negative"
      qualifier: non_negative_stocks
      expression: >
        stock_on_hand < 0
        OR stock_reserved < 0
        OR stock_available < 0
  - failed_rows:
      name: "Reserved stock cannot exceed stock on hand"
      qualifier: reserved_le_on_hand
      expression: stock_reserved > stock_on_hand
  - failed_rows:
      name: "Available stock must equal on_hand minus reserved"
      qualifier: available_equals_on_hand_minus_reserved
      expression: stock_available <> (stock_on_hand - stock_reserved)
  - failed_rows:
      name: "last_updated_at must not be in the future"
      qualifier: last_updated_not_future
      expression

columns:
  - name: product_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: location_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: stock_on_hand
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Stock on hand must be zero or positive"
          valid_min: 0
  - name: stock_reserved
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Reserved stock must be zero or positive"
          valid_min: 0
  - name: stock_available
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Available stock must be zero or positive"
          valid_min: 0
  - name: last_updated_at
    data_type: dateTime
    checks:
      - missing

Data contract description

This data contract enforces schema stability, a 24-hour freshness SLA, and required product/location identifiers and update timestamps. It prevents missing or invalid stock values, blocks negative inventory states, ensures reserved stock never exceeds on-hand stock, and enforces that available stock correctly reflects on-hand minus reserved. Together, these checks reduce overselling risk, prevent broken availability signals in ecommerce and stores, and protect replenishment, allocation, and fulfillment processes.

inventory_levels_data_contract.yml

dataset
variables:
  FRESHNESS_HOURS:
    default: 24

checks:
  - schema: {}
  - row_count:
      threshold:
        must_be_greater_than: 0
  - freshness:
      column: last_updated_at
      threshold:
        unit: hour
        must_be_less_than_or_equal: ${var.FRESHNESS_HOURS}
  - failed_rows:
      name: "Stock values must never be negative"
      qualifier: non_negative_stocks
      expression: >
        stock_on_hand < 0
        OR stock_reserved < 0
        OR stock_available < 0
  - failed_rows:
      name: "Reserved stock cannot exceed stock on hand"
      qualifier: reserved_le_on_hand
      expression: stock_reserved > stock_on_hand
  - failed_rows:
      name: "Available stock must equal on_hand minus reserved"
      qualifier: available_equals_on_hand_minus_reserved
      expression: stock_available <> (stock_on_hand - stock_reserved)
  - failed_rows:
      name: "last_updated_at must not be in the future"
      qualifier: last_updated_not_future
      expression

columns:
  - name: product_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: location_id
    data_type: string
    checks:
      - missing:
          name: No missing values
  - name: stock_on_hand
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Stock on hand must be zero or positive"
          valid_min: 0
  - name: stock_reserved
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Reserved stock must be zero or positive"
          valid_min: 0
  - name: stock_available
    data_type: integer
    checks:
      - missing:
      - invalid:
          name: "Available stock must be zero or positive"
          valid_min: 0
  - name: last_updated_at
    data_type: dateTime
    checks:
      - missing

How to Enforce Data Contracts with Soda

Embed data quality through data contracts at any point in your pipeline.

Embed data quality through data contracts at any point in your pipeline.

# pip install soda-{data source} for other data sources

pip install soda-postgress

# verify the contract locally against a data source

soda contract verify -c contract.yml -ds ds_config.yml

# publish and schedule the contract with Soda Cloud

soda contract publish -c contract.yml -sc sc_config.yml

Check out the CLI documentation to learn more.

Check out the CLI documentation to learn more.

How to Automatically Create Data Contracts.
In one Click.

Automatically write and publish data contracts using Soda's AI-powered data contract copilot.

Make data contracts work in production

Business knows what good data looks like. Engineering knows how to deliver it at scale. Soda unites both, turning governance expectations into executable contracts.

Make data contracts work in production

Business knows what good data looks like. Engineering knows how to deliver it at scale. Soda unites both, turning governance expectations into executable contracts.

Make data contracts work in production

Business knows what good data looks like. Engineering knows how to deliver it at scale. Soda unites both, turning governance expectations into executable contracts.

4.4 of 5

Start trusting your data. Today.

Find, understand, and fix any data quality issue in seconds.
From table to record-level.

Trusted by

4.4 of 5

Start trusting your data. Today.

Find, understand, and fix any data quality issue in seconds.
From table to record-level.

Trusted by

4.4 of 5

Start trusting your data. Today.

Find, understand, and fix any data quality issue in seconds.
From table to record-level.

Trusted by