Skip to content

Load File

You have an object on disk - a pickled or joblib model from a colleague, or a JSON lookup - and you want to apply it to your data. The Load File node loads the file as obj, and you apply it in the node's TRANSFORM tab: add a Free code step.

When to use

  • Your model is a standalone file not tracked in MLflow (e.g. a .pkl from a colleague), and its class is one Haute can load (see the warning below).
  • You need to load a JSON lookup file and apply it with custom logic.
  • To score a model Haute trains (CatBoost, GLM, XGBoost, LightGBM, t-boost or EBM), from MLflow or from a file in the project, use Model Scoring instead: it checks the model's features and offset for you.

A Load File node takes the data to score as its first input and outputs that data with whatever your steps or code add. Your steps and code see the first input as df; any further inputs are available by their names, and Join another input and Append inputs steps can use them. With no steps and no code, the node passes its first input through unchanged. The panel has three tabs: CONFIG, TRANSFORM and COLUMNS.

Inside a submodel, code keeps the input names it was written against when another frame is bound to a public input. This applies to the owner and every instance, in previews and in the deployed bundle. Instance on a Load File node creates a shared one-node submodel; see Reusing a node.

The CONFIG tab

The INPUT chips at the top name the node's connections; the × on a chip removes that connection. Below them:

Field What it does
FILE TYPE How to read the file: PICKLE (the default), JSON or JOBLIB.
FILE PATH The file, chosen in the file browser: a .pkl, .pickle, .json or .joblib file inside your project folder. Once a file is chosen, change opens the browser again.

Pickle and joblib files load only known classes

For safety, Haute loads pickle and joblib files through an exact list of allowed classes: NumPy arrays, pandas and Polars DataFrames and Series, plain Python values such as dictionaries and lists, CatBoost models, scikit-learn's RandomForestRegressor, LinearRegression and DecisionTreeRegressor, and InterpretML's ExplainableBoostingRegressor and ExplainableBoostingClassifier. Any other class fails with "Blocked unpickling of ...". That includes other scikit-learn estimators (classifiers among them) and pickled XGBoost or LightGBM models, which fail naming their own class (such as "Blocked unpickling of xgboost.sklearn.XGBRegressor"); save such a model in its own format (.ubj or .lgbm) and score it with Model Scoring.

The TRANSFORM tab

See Transform.

The COLUMNS tab

The COLUMNS tab chooses which columns the node passes on (see Working with any node).

Example

To score your data with a model saved as models/frequency.pkl:

  1. Connect your data to a Load File node. On the CONFIG tab, leave FILE TYPE on PICKLE and choose models/frequency.pkl under FILE PATH.
  2. On the TRANSFORM tab, click Add step and choose Free code.
  3. Type this in the step's code box:
feature_columns = ["driver_age", "vehicle_age", "area"]  # columns your model was trained on
predictions = obj.predict(df.select(feature_columns).collect().to_pandas())
df = df.with_columns(pl.Series("prediction", predictions))

Reading the code:

Expression What it does
obj The loaded file (your model, lookup table, etc.)
df The input data as a table (dataframe)
obj.predict(...) Asks the model to produce predictions
feature_columns = [...] A list of column names your model was trained on - replace with your own
df.select(feature_columns) Picks those columns from the table
.collect() Reads the data, so the model gets actual rows (df is a lazy table until then)
.to_pandas() Converts the data to the format most models expect - you'll see this in most scoring code
pl.Series("prediction", predictions) Wraps the results as a new column called "prediction"
df.with_columns(...) Adds the new column to the table

The preview then shows your data with a new prediction column.

Assign the result to df

Your code must assign its result to df, which Haute passes to the next node. Do not add return df: a Free code step refuses it ("Assign the result to df instead of using return.").

JSON lookup example

If your file is a JSON dictionary (e.g. area factors), choose JSON as the FILE TYPE and use it as a lookup table in a Free code step. Areas missing from the dictionary get a factor of 1.0:

# obj is a dict loaded from a JSON file, e.g. {"London": 1.25, "Rural": 0.85}
df = df.with_columns(
    pl.col("area").replace_strict(obj, default=1.0).alias("area_factor")
)
In the pipeline file

The node's settings are stored in a JSON sidecar, config/load_file/<node name>.json, which the node's decorator in the pipeline's .py file names: @pipeline.external_file(config="config/load_file/<node name>.json"). Steps on the TRANSFORM tab are stored in the sidecar as steps, and the code they generate is the body of the node's function, which takes the node's inputs and the loaded object as obj; a body edited by hand so that it no longer matches the steps is the node's code, shown in a code box.

Setting in the editor Stored as
FILE TYPE file_type: "pickle", "json" or "joblib"
FILE PATH path: the file, relative to your project folder
TRANSFORM tab the function body, which Haute reads the steps back from
COLUMNS tab selected_columns

Every key the config may hold:

Key Type Description
code text The Polars code the node's function runs; when steps are present, their rendering.
steps list of map of text to any JSON value The low-code steps, in order, rebuilt from the node's code each time it loads; the config file does not hold them.
path text The file, relative to the project root.
file_type "pickle" or "json" or "joblib" How the file is loaded.
input_mapping map of text to text The input names the node's code uses, each mapped to the connected input it reads.
contract "opaque" or object The node's column contract as its decorator declares it: "opaque", or the columns it reads and produces.
selected_columns list of text The columns the node passes downstream, chosen on its Columns tab; absent passes all.
column_renames map of text to text New names for columns passed downstream, from each column's name to its new one.

See also: