{"record":{"id":"6cc8767418492d66","repo":"deepset-ai/haystack","slug":"cls-name-must-have-a-run-method-see-the","errorCode":null,"errorMessage":"{cls.__name__} must have a 'run()' method. See the docs for more information.","messagePattern":"(.+?) must have a 'run\\(\\)' method\\. See the docs for more information\\.","errorType":"exception","errorClass":"ComponentError","httpStatus":null,"severity":"error","filePath":"haystack/core/component/component.py","lineNumber":571,"sourceCode":"\n            setattr(  # noqa: B010\n                run_method,\n                \"_output_types_cache\",\n                {name: OutputSocket(name=name, type=type_) for name, type_ in types.items()},\n            )\n            return run_method\n\n        return output_types_decorator\n\n    def _component(self, cls: type[T]) -> type[T]:\n        \"\"\"\n        Decorator validating the structure of the component and registering it in the components registry.\n        \"\"\"\n        logger.debug(\"Registering {component} as a component\", component=cls)\n\n        # Check for required methods and fail as soon as possible\n        if not hasattr(cls, \"run\"):\n            raise ComponentError(f\"{cls.__name__} must have a 'run()' method. See the docs for more information.\")\n\n        def copy_class_namespace(namespace: dict[str, Any]) -> None:\n            \"\"\"\n            This is the callback that `typing.new_class` will use to populate the newly created class.\n\n            Simply copy the whole namespace from the decorated class.\n            \"\"\"\n            for key, val in dict(cls.__dict__).items():\n                # __dict__ and __weakref__ are class-bound, we should let Python recreate them.\n                if key in (\"__dict__\", \"__weakref__\"):\n                    continue\n                namespace[key] = val\n\n        # Recreate the decorated component class so it uses our metaclass.\n        # We must explicitly redefine the type of the class to make sure language servers\n        # and type checkers understand that the class is of the correct type.\n        new_cls: type[T] = new_class(cls.__name__, cls.__bases__, {\"metaclass\": ComponentMeta}, copy_class_namespace)\n","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/component/component.py#L553-L589","documentation":"The @component class decorator validates a class's structure before registering it in the component registry. Every Haystack component must expose a 'run' method, since pipelines invoke it; a class lacking one fails this check with a ComponentError at decoration time.","triggerScenarios":"Applying @component to a class that defines no 'run' method — e.g. the method is named differently (execute, __call__, run_async only with no run in older versions), or it is defined only dynamically/in a base class that's not actually inherited.","commonSituations":"Renaming 'run' during refactoring while keeping @component; wrapping the class with a metaclass or tool that strips methods; defining run as an instance attribute (self.run = ...) instead of a method; subclassing a Protocol instead of a concrete component.","solutions":["Add a 'run' method (and optionally 'run_async') to the class, decorated with @component.output_types if needed","Check the method name spelling — it must be exactly 'run'","If the class should not be a component, remove the @component decorator"],"exampleFix":"// before\n@component\nclass MyComponent:\n    def execute(self, x: int) -> dict: ...\n\n// after\n@component\nclass MyComponent:\n    @component.output_types(int)\n    def run(self, x: int) -> dict[str, int]: ...","handlingStrategy":"validation","validationCode":"def validate_component(cls) -> None:\n    if not callable(getattr(cls, \"run\", None)):\n        raise TypeError(f\"{cls.__name__} must define a 'run' method before @component is applied\")","typeGuard":"def is_valid_component(cls) -> bool:\n    return callable(getattr(cls, \"run\", None))","tryCatchPattern":"try:\n    @component\n    class C: ...\nexcept ComponentError as e:\n    logging.error(\"Component structure invalid: %s\", e)","preventionTips":["Always define run() before adding the @component decorator","Keep run as a real method, not an instance attribute","Add a unit test that instantiates every custom component"],"tags":["python","component","haystack","decorator"],"backgroundTag":"missing-required-method","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}