def {{ function_name }}({{ function_args|join(', ') }}) -> str:

    import os
    import shutil
    from kale.marshal import resource_save as _kale_resource_save
    from kale.marshal import resource_load as _kale_resource_load

    _kale_data_directory = "/marshal/{{ pipeline_name }}/"
    _input_data_folder = "/data/{{ pipeline_name }}/"

    # -----------------------DATA LOADING START--------------------------------
{%- if in_variables|length > 0 %}
    {# Check directory exists #}
    if not os.path.isdir(_kale_data_directory):
        raise ValueError(_kale_data_directory + " directory does not exist")

    _kale_directory_file_names = [
        os.path.splitext(f)[0]
        for f in os.listdir(_kale_data_directory)
        if os.path.isfile(_kale_data_directory + f)
    ]
{%- endif %}

{%- for in_var in in_variables %}
    {# First check that the variable exists in the path #}
    if "{{ in_var }}" not in _kale_directory_file_names:
        raise ValueError("{{ in_var }}" + " does not exists in directory")

    {# Load variable -#}
    _kale_load_file_name = [
        f
        for f in os.listdir(_kale_data_directory)
        if os.path.isfile(_kale_data_directory + f) and
           os.path.splitext(f)[0] == "{{ in_var }}"
    ]
    if len(_kale_load_file_name) > 1:
        raise ValueError("Found multiple files with name " + "{{ in_var }}" + ": " + str(_kale_load_file_name))
    _kale_load_file_name = _kale_load_file_name[0]
    {{ in_var }} = _kale_resource_load(_kale_data_directory + _kale_load_file_name)
{%- endfor %}
    # -----------------------DATA LOADING END----------------------------------


{% for block in function_blocks %}
{{block|indent(4, True)}}
{% endfor %}
    # -----------------------DATA SAVING START---------------------------------
{%- if out_variables|length > 0 %}
    if not os.path.isdir(_kale_data_directory):
        os.makedirs(_kale_data_directory, exist_ok=True)
{%- endif %}

{%- for out_var in out_variables %}
    if "{{ out_var }}" in locals():
        {#-  `_kale_resource_save` will automatically add the correct extension #}
        _kale_resource_save({{ out_var }}, _kale_data_directory + "{{ out_var }}")
    else:
        print("_kale_resource_save: `{{ out_var }}` not found.")
{%- endfor %}
    # -----------------------DATA SAVING END-----------------------------------
