Schedule icon
Write icon
Script icon
Docker icon
If icon
Fail icon

ML Feature Contract-Gated Training

Stop model training on stale or missing features, audit validation results, and train a regression model on approved data.

Categories
Data

Validate an ML feature batch against a versioned availability contract and execute real least-squares model training only when it passes. Rejected batches stop before any training artifact is produced. The sample predicts next_month_spend using transaction_count_30d, without external APIs.

How it works

  1. A disabled daily UTC Schedule illustrates recurring use; execute manually with a candidate CSV, JSON contract, and evaluation timestamp.
  2. stage_candidate stores immutable execution input bytes.
  3. validate_availability checks contract shape, required columns, null and stale fractions, invalid/future timestamps, minimum rows, and the share of rows where every required feature is present and fresh. It writes audit.json.
  4. availability_gate writes a checksum-bound approval manifest only after an explicit success. train_spend_model verifies that manifest, audit, and dataset hash, then fits a least-squares predictor on usable records and saves a model. The rejection branch fails without executing the training task.

What you get

  • Per-feature counts and thresholds, joint usable-row coverage, failure reasons, and dataset/contract SHA-256 fingerprints in audit.json.
  • On success, an approval JSON manifest plus trained-model.json containing fitted coefficients, training row count, MAE, and dataset fingerprint.
  • Fail-closed behavior for missing columns, malformed inputs, or unsafe timestamps. Approval covers the batch, not a filtered dataset of exclusively usable rows.

Who it's for

ML engineers, data engineers, and platform teams validating assembled feature batches before downstream training or evaluation jobs.

Why orchestrate this with Kestra

Kestra persists dataset and audit artifacts and enforces task dependencies: train_spend_model exists only inside the approved If branch. Invalid input cannot produce a model, unlike a standalone scheduled validation script.

Prerequisites

  • Kestra 2.0 with Core and the Python Script plugin.
  • A Docker-capable worker able to pull python:3.13-slim.
  • No network API, third-party Python packages, or external services required.
  • The default timestamp is fixed for reproducible sample CSV execution; use a current batch time or empty evaluation_time for real workloads.

Secrets

  • None. The supplied sample data is illustrative and requires no credentials.

Quick start

  1. Import the flow and execute with default CSV, contract, and evaluation_time.
  2. Inspect the approval manifest, audit.json, and trained-model.json task artifact on success; the model has fitted slope, intercept, and training MAE.
  3. Blank one customer_age cell; rerun and confirm reject_candidate fails and train_spend_model is skipped. Try a stale timestamp for another failure.
  4. Supply an actual CSV and contract. Wire a fresh upstream dataset source before enabling the disabled illustrative daily Schedule.

How to extend

  • Replace the inline CSV input with object-storage ingestion for large files.
  • Replace the illustrative single-feature regression with a production training command, keeping it inside the approved branch with checksum verification.
  • Add model evaluation, deployment approval, and failure notifications.
  • Add feature type, range, or point-in-time correctness checks separately; this workflow does not detect target leakage or sanitize unusable rows.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.