{"record":{"id":"e1e8e1d2aec55969","repo":"deepset-ai/haystack","slug":"cannot-set-input-types-on-a-component-that-doesn-t","errorCode":null,"errorMessage":"Cannot set input types on a component that doesn't have a kwargs parameter in the 'run' method","messagePattern":"Cannot set input types on a component that doesn't have a kwargs parameter in the 'run' method","errorType":"exception","errorClass":"ComponentError","httpStatus":null,"severity":"error","filePath":"haystack/core/component/component.py","lineNumber":432,"sourceCode":"    def set_input_type(\n        self,\n        instance: Component,\n        name: str,\n        type: Any,  # noqa: A002\n        default: Any = _empty,\n    ) -> None:\n        \"\"\"\n        Add a single input socket to the component instance.\n\n        Replaces any existing input socket with the same name.\n\n        :param instance: Component instance where the input type will be added.\n        :param name: name of the input socket.\n        :param type: type of the input socket.\n        :param default: default value of the input socket, defaults to _empty\n        \"\"\"\n        if not _component_run_has_kwargs(instance.__class__):\n            raise ComponentError(\n                \"Cannot set input types on a component that doesn't have a kwargs parameter in the 'run' method\"\n            )\n\n        if not hasattr(instance, \"__haystack_input__\"):\n            instance.__haystack_input__ = Sockets(instance, {}, InputSocket)  # type: ignore\n        instance.__haystack_input__[name] = InputSocket(name=name, type=type, default_value=default)  # type: ignore\n\n    def set_input_types(self, instance: Any, **types: type[Any]) -> None:\n        \"\"\"\n        Method that specifies the input types when 'kwargs' is passed to the run method.\n\n        Use as:\n\n        ```python\n        @component\n        class MyComponent:\n\n            def __init__(self, value: int) -> None:","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/component/component.py#L414-L450","documentation":"component.set_input_type() can only dynamically declare an input socket on components whose run method has a **kwargs parameter, because the socket has no corresponding named parameter to attach to otherwise. Calling it on such a component raises ComponentError.","triggerScenarios":"Calling set_input_type(instance, name, type) (or with a default) on a component whose run signature is fully explicit (no **kwargs).","commonSituations":"Trying to add an extra optional input (like a retry_count or metadata) to a component with a fixed run signature; following docs examples for kwargs-based components while your component uses named params.","solutions":["Add `**kwargs` to the run method signature (and to run_async to keep them in sync), then call set_input_type","Declare the input statically in the run signature instead of using set_input_type","Use the @component.input_types decorator on run to declare inputs declaratively"],"exampleFix":"# before\nclass C:\n    def run(self, x: int):\n        return {\"y\": x}\nset_input_type(C(), \"extra\", str)  # raises\n\n# after\nclass C:\n    def run(self, x: int, **kwargs):\n        return {\"y\": x}\n\ncomp = C()\nset_input_type(comp, \"extra\", str, default=None)","handlingStrategy":"validation","validationCode":"from haystack.core.component.component import _component_run_has_kwargs\nif not _component_run_has_keywords(type(comp)) if False else True:\n    pass\ndef can_set_input_type(comp_cls) -> bool:\n    sig = inspect.signature(comp_cls.run)\n    return any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values())","typeGuard":"def run_accepts_kwargs(cls) -> bool:\n    import inspect\n    return any(\n        p.kind == inspect.Parameter.VAR_KEYWORD\n        for p in inspect.signature(cls.run).parameters.values()\n    )","tryCatchPattern":"try:\n    set_input_type(comp, \"extra\", str)\nexcept ComponentError as e:\n    logging.error(\"Add **kwargs to run() before calling set_input_type\")\n    raise","preventionTips":["If you plan to mutate inputs dynamically, author run with **kwargs from the start","Check the run signature with inspect for VAR_KEYWORD before calling set_input_type","Prefer static named parameters when inputs are fixed"],"tags":["python","haystack","component","sockets","kwargs"],"backgroundTag":"set-input-type-requires-kwargs","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}