Hi, Is there a way to pass dict variable in kedro...
# questions
f
Hi, Is there a way to pass dict variable in kedro node inputs? Example:
Copy code
node(myfunc, inputs=dict(x="ds1", y=dict(subv="test1", subc="test2"))
Basically i would expect kedro to pass the resolved dict into the node as a dict. Right now it's not possible as kedro complains and wants the values as string. Not really sure how to get around that
d
You can partially apply the functions using
functools
, I’ve long wanted a
Literal
operator for this
f
hmm, how can you do that with functools? My brain does not work atm 😄
The only way i know is to make this a string and do complex string parsing by overloading catalog but that's gonna look pretty ugly
j
d
Copy code
from functools import partial, update_wrapper
from kedro.pipeline import node

# Original lambda
add = lambda x, y: x + y

# Partially apply x=10
add_10 = partial(add, 10)
update_wrapper(add_10, add)  # Optional, preserves metadata

# Create Kedro node
add_node = node(
    func=add_10,
    inputs="input_y",     # only 'y' is needed now
    outputs="output_sum",
    name="add_10_node"
)
👍 1
this is what I was trying to describe on my phone
I would love if we could do
from kedro.pipeline import Literal
so you didn't have to do this hack
f
I found a workaround, commented in github which is this: My current working solution:
Copy code
@node_kwargs(
    inputs=dict(
        text=ds.TEXT,
        models=ModelGroup(
            free="master:deepseek-v3-0324::worker:gemini-2.5-flash",
            plus="master:gpt-4o::worker:gemini-2.5-pro",
            pro="master:claude-sonnet::worker:gemini-2.5-pro",
        ).to_string(),
        prompts=prompt_param,
        max_shot=param("max_shot"),
    ),
    outputs=ds.RESPONSE
)
Notice the ModelGroup has
to_string
method. I basically serialize this class into json and in the custom Catalog class during the load i deserialize it again. After that for each value i invoke kedro load and return the combine class. I have my custom node decorator so going towards lambda wasn't easy for me. Happy to get it working due to flexibility and customization in kedro 😄
👍 1
👏 1