Brief
Write and apply a shape contract for supplier events, then explain what a version change may break.
Mara puts a supplier page in front of you. Voss insists, “the operator was the recruit.” Yet practice v2 row TRANSFER-7 lacks operator_id, while E8 has it. Imani must report what the delivery actually says without filling gaps for either side. In the story she waits for your check before a meeting; the lesson has no timer.
Your mission
- List the required fields and types in this v2 contract.
- Classify E8 and TRANSFER-7 using the validator and name the exact error.
- Explain why assigning your ID to the missing operator_id would be false.
- Say what to do if the supplier still sends a version 1 message.
How to check your work
- schema_version is int; six other fields are nonempty text.
- E8 passes; TRANSFER-7 lacks operator_id.
- A guess about identity must not replace absent data.
- Version 1 follows an explicit older rule or migration, not invented compliance.
Course example
REQUIRED = {
"schema_version": int,
"event_id": str,
"event_type": str,
"event_at": str,
"vehicle_label": str,
"operator_id": str,
"source_file": str,
}
def check_event(event):
if not isinstance(event, dict):
return ["event must be an object"]
errors = []
for field, kind in REQUIRED.items():
if field not in event:
errors.append(f"missing {field}")
elif type(event[field]) is not kind:
errors.append(f"wrong type for {field}")
elif kind is str and not event[field].strip():
errors.append(f"empty {field}")
if "schema_version" in event and event["schema_version"] != 2:
errors.append("expected schema_version 2")
return errors
complete = {
"schema_version": 2, "event_id": "E8", "event_type": "TRANSFER",
"event_at": "2026-04-12T21:25:00Z", "vehicle_label": "NOCTIS-01",
"operator_id": "OP-17", "source_file": "supplier-page3.json"
}
critical = {**complete, "event_id": "TRANSFER-7"}
del critical["operator_id"]
print(check_event(complete))
print(check_event(critical))