Skip to content

ump_spec.models.contract

module ump-spec

Workflow input contract: the “same necessary shape” a saved workflow accepts on new data.

A saved model plus its data pipeline reruns on new input when the input has the columns it needs, castable to their types, with keys unique and time regular. Rows are unbounded above (more weeks is the normal case); extra columns never fail. The check (rules.contract.check_input) is pure: it reads a FrameProfile the caller built (babelfin builds one with pandas), never the rows, so ump_spec imports no dataframe library.

Privacy: category level sets are stored as a sha256 of the sorted level values plus a count, and a sha256 per level, never the values. A per-level hash lets the check name the rows at a new level (to exclude them) without the values; like any unsalted hash of a short string it can be matched by someone who guesses the value.

class

class InputVar(VarSpec)

A variable the workflow reads. required: false makes it optional: absent gives a warning.

Fields

NameTypeDefaultDescription
requiredboolTrue

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 30

class

class LevelSet(StrictModel)

A categorical column’s levels without the values: the sha256 (hex) of the canonical JSON of the sorted unique non-null level values (as strings), their count, and the sorted sha256 of each level’s canonical JSON (empty in contracts written before per-level hashes; the check then compares the set hash and count only).

Fields

NameTypeDefaultDescription
sha256str
countint
hasheslist[Annotated[str, Field(pattern=HEX64)]]list()sha256 (hex) of each level’s canonical JSON string, sorted; never values.

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 39

class

class InputContract(StrictModel)

What new input must look like for a saved workflow to rerun on it.

Fields

NameTypeDefaultDescription
schema_versionstrINPUT_CONTRACT_VERSION
timestr | NoneNoneThe time column, if any; its dim (policy, freq) is in dims.
dimsdict[str, DimSpec]dict()
varsdict[str, InputVar]dict()
targetstr | NoneNoneThe target column; required to refit, not to score.
target_dtypestr | NoneNoneThe target’s dtype; on a refit the target must cast to it and have no missing values.
keylist[str]list()Columns that identify a row (each one required); empty means the time column plus the categorical dims.
extraLiteral['allow', 'drop']'drop'Columns the contract does not name: drop (info note) or allow (passed silently). Never a failure.
min_rowsint | NoneNoneFewest rows the workflow expects (proposed; below it is a warning).
level_setsdict[str, LevelSet]dict()Trained level set per fixed categorical dim (hash and count, never values).

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 50

class

class ColumnProfile(StrictModel)

One column of the input frame. cast is the caller’s cast result to the contract dtype (None when the contract names no dtype for the column).

Fields

NameTypeDefaultDescription
dtypestr
n_nullint0
castCastResult | NoneNone

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 73

class

class TimeProfile(StrictModel)

The time column of the input frame. duplicates counts rows whose time value repeats (expected in a panel); regular is false when a time is off the frequency’s grid; gaps counts missing steps inside the range at the frequency.

Fields

NameTypeDefaultDescription
minstr
maxstr
n_uniqueint
duplicatesint0
regularboolTrue
gapsint0

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 82

class

class CategoryProfile(StrictModel)

A categorical column’s level set in the input frame (hashes and count, never values). rows counts the rows per level hash, so a note can say how many rows a new level excludes.

Fields

NameTypeDefaultDescription
level_setLevelSet
rowsdict[str, int]dict()Level hash to row count (optional).

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 95

class

class FrameProfile(StrictModel)

Everything the input check reads about a frame, with no row values in it.

Fields

NameTypeDefaultDescription
n_rowsint
columnsdict[str, ColumnProfile]dict()
timeTimeProfile | NoneNone
key_duplicatesint0
categoriesdict[str, CategoryProfile]dict()

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 103

class

class InputNote(StrictModel)

One finding about the input, in plain words. Never carries row values.

Fields

NameTypeDefaultDescription
codestr
severityInputSeverity
columnstr | NoneNone
messagestr

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 113

class

class InputReport(StrictModel)

The outcome of checking input against a workflow’s contract. ok is false when a note refuses; route is where the rerun goes (score, refit, or not available).

Fields

NameTypeDefaultDescription
okbool
modeInputMode'score'
routeInputRoute'score'
noteslist[InputNote]list()
drop_columnslist[str]list()
coercedict[str, str]dict()Column to the contract dtype it is cast to.
exclude_levelsdict[str, list[str]]dict()Column to the hashes of its new levels; rows at those levels are excluded.
exclude_nullslist[str]list()Structural columns (time, categorical dims, key) whose rows with no value are excluded.

Source: packages/ump-spec/src/ump_spec/models/contract.py, line 122

NameTypeValueDescription
INPUT_CONTRACT_VERSION'ump.input_contract/0.1'
InputSeverityLiteral['info', 'warn', 'exclude', 'refuse']
InputModeLiteral['score', 'refit']
InputRouteLiteral['score', 'refit', 'not_available']
CastResultLiteral['exact', 'coerced', 'failed']
HEX64'^[0-9a-f]{64}$'