@validate_schema(required_keys={"order_id", "customer_id", "amount", "status"}) def normalize_order(order: dict) -> dict: return { "order_id": order["order_id"], "customer_id": order["customer_id"], "amount": round(float(order["amount"]), 2), "status": order["status"].lower().strip(), "note": order.get("note", ""), # optional — fine to be absent } # Valid record — passes through normalize_order({"order_id": 1, "customer_id": 101, "amount": "59.99", "status": "Completed"}) # {"order_id": 1, "customer_id": 101, "amount": 59.99, "status": "completed", "note": ""} # Missing amount — caught immediately normalize_order({"order_id": 2, "customer_id": 102, "status": "Completed"}) # ValueError: Missing required keys: {'amount'} # Wrong type entirely — also caught normalize_order([1, 101, 59.99, "completed"]) # TypeError: Expected dict, got list