diff --git a/flytekit/core/interface.py b/flytekit/core/interface.py index 7f0af5f8e6..ca184fa5e0 100644 --- a/flytekit/core/interface.py +++ b/flytekit/core/interface.py @@ -3,6 +3,7 @@ import collections import copy import inspect +import re import typing from collections import OrderedDict from typing import Any, Dict, Generator, List, Optional, Tuple, Type, TypeVar, Union, cast @@ -21,6 +22,7 @@ from flytekit.models.literals import Literal, Scalar, Void T = typing.TypeVar("T") +_PYTHON_VARIABLE_NAME_REGEX = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$') def repr_kv(k: str, v: Union[Type, Tuple[Type, Any]]) -> str: @@ -261,6 +263,12 @@ def transform_interface_to_typed_interface( interface.docstring.output_descriptions, interface.outputs ) + # Assert valid interface variable names + for key in interface.inputs.keys(): + assert _PYTHON_VARIABLE_NAME_REGEX.match(key), f"Invalid input name: '{key}'. Inputs must be valid Python variable names." + for key in interface.outputs.keys(): + assert _PYTHON_VARIABLE_NAME_REGEX.match(key), f"Invalid output name: '{key}'. Outputs must be valid Python variable names." + inputs_map = transform_variable_map(interface.inputs, input_descriptions) outputs_map = transform_variable_map(interface.outputs, output_descriptions) verify_outputs_artifact_bindings(interface.inputs, outputs_map, allow_partial_artifact_id_binding)