Typed parameter validation binds a params: input to the wrong function argument when a node skips an argument
Description
When a node is declared with a dict of inputs and the function has a parameter that the node does not provide, parameter validation maps the params: input to the wrong function argument. The typed requirement is then taken from an argument the node never receives, and kedro run fails with a validation error for a type the user never asked for.
TypeExtractor._build_dataset_to_arg_mapping maps inputs to arguments by position:
elif isinstance(node_inputs, list | tuple):
sig_param_names = list(signature.parameters.keys())
for idx, ds in enumerate(node_inputs):
if idx < len(sig_param_names):
dataset_to_arg[ds] = sig_param_names[idx]Node.inputs only lists the datasets the node actually provides (for a dict it goes through _dict_inputs_to_list, which binds them to the signature). The signature, on the other hand, lists every parameter, including the ones left to their defaults. As soon as one of those sits before a provided argument, the two lists are out of step and every input after it is attributed to the wrong name.
Note that the isinstance(node_inputs, dict) branch just above is unreachable, since Node.inputs always returns a list. If it did run it would also be inverted, because a node's input dict is {argument: dataset} while the mapping is built as {dataset: argument}.
Context
The shape that triggers this is ordinary: a function with an optional config argument and a couple of tunables, where the node only wires the tunables.
def train(data: int, config: TrainConfig | None = None, seed: int = 0) -> int: ...
node(train, inputs={"data": "raw", "seed": "params:seed"}, outputs="m", name="train")node.inputs is ['raw', 'params:seed'] and the signature is ['data', 'config', 'seed'], so params:seed is attributed to config. Validation then requires the seed parameter to be a TrainConfig, and the run stops before any node executes. config is not even passed by this node.
The failure is hard to read, because the error names a model that has nothing to do with the parameter being validated.
Steps to Reproduce
- In a project, add to
conf/base/parameters.yml:
seed: 42- Add a pipeline with the node above:
from pydantic import BaseModel
from kedro.pipeline import Pipeline, node
class TrainConfig(BaseModel):
lr: float
def make_data() -> int:
return 1
def train(data: int, config: TrainConfig | None = None, seed: int = 0) -> int:
return data + seed
def create_pipeline(**kwargs) -> Pipeline:
return Pipeline([
node(make_data, None, "raw", name="make_data"),
node(train, inputs={"data": "raw", "seed": "params:seed"}, outputs="m", name="train"),
])- Run
kedro run.
The mapping can also be inspected directly:
from kedro.validation.type_extractor import TypeExtractor
TypeExtractor({"__default__": Pipeline([n])}).extract_types_from_pipelines()
# {'seed': TrainConfig} expected: {}Expected Result
params:seed is matched to the seed argument. Since int is neither a Pydantic model nor a dataclass, no requirement is recorded and the run proceeds.
Actual Result
ERROR Parameter 'seed': Failed to instantiate TrainConfig for parameter 'seed'
ParameterValidationError: Parameter validation failed:
- Parameter 'seed': Failed to instantiate TrainConfig for parameter 'seed': 1 validation errorYour Environment
- Kedro version used: 1.6.0 (installed from source at
8d9abdf) - Python version used: 3.12.13
- Operating system and version: macOS 15
Possible fix
Build the mapping from the node's own input declaration instead of by position, so the argument name comes from the same binding that Node.inputs uses, and drop or correct the unreachable dict branch. I have a fix and a regression test ready and I am happy to open a PR if you agree with the approach.
Source: kedro-org/kedro