{"record":{"id":"59f0985100e4fbfe","repo":"deepset-ai/haystack","slug":"cannot-call-set-output-types-on-a-component-that","errorCode":null,"errorMessage":"Cannot call `set_output_types` on a component that already has the 'output_types' decorator on its `run` or `run_async` methods.","messagePattern":"Cannot call `set_output_types` on a component that already has the 'output_types' decorator on its `run` or `run_async` methods\\.","errorType":"exception","errorClass":"ComponentError","httpStatus":null,"severity":"error","filePath":"haystack/core/component/component.py","lineNumber":516,"sourceCode":"        class MyComponent:\n\n            def __init__(self, value: int) -> None:\n                component.set_output_types(self, output_1=int, output_2=str)\n                ...\n\n            # no decorators here\n            def run(self, value: int):\n                return {\"output_1\": 1, \"output_2\": \"2\"}\n\n            # also no decorators here\n            async def run_async(self, value: int):\n                return {\"output_1\": 1, \"output_2\": \"2\"}\n        ```\n        \"\"\"\n        has_run_decorator = hasattr(instance.run, \"_output_types_cache\")\n        has_run_async_decorator = hasattr(instance, \"run_async\") and hasattr(instance.run_async, \"_output_types_cache\")\n        if has_run_decorator or has_run_async_decorator:\n            raise ComponentError(\n                \"Cannot call `set_output_types` on a component that already has the 'output_types' decorator on its \"\n                \"`run` or `run_async` methods.\"\n            )\n\n        instance.__haystack_output__ = Sockets(\n            instance, {name: OutputSocket(name=name, type=type_) for name, type_ in types.items()}, OutputSocket\n        )\n\n    def output_types(\n        self, **types: Any\n    ) -> Callable[[Callable[RunParamsT, RunReturnT]], Callable[RunParamsT, RunReturnT]]:\n        \"\"\"\n        Decorator factory that specifies the output types of a component.\n\n        Use as:\n        ```python\n        @component\n        class MyComponent:","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/component/component.py#L498-L534","documentation":"If run (or run_async) is already decorated with @component.output_types, the output sockets are fixed by the decorator and must not be overridden. Calling component.set_output_types() on such an instance raises ComponentError to prevent silently conflicting output definitions.","triggerScenarios":"Calling set_output_types(instance, {...}) on a component whose run method has _output_types_cache (applied by @component.output_types) or whose run_async has it.","commonSituations":"Mixing the decorator-based and imperative APIs to configure the same component; subclassing a decorated component and trying to change outputs at runtime; copy-pasting set_output_types code into a component that already uses the decorator.","solutions":["Remove the @component.output_types decorator from run/run_async if you want to set outputs imperatively via set_output_types","Remove the set_output_types call and rely on the decorator's output definition instead","Merge the desired outputs into the decorator's argument list rather than calling set_output_types"],"exampleFix":"# before\nclass C:\n    @component.output_types(out=str)\n    def run(self, x: int):\n        return {\"out\": str(x)}\n\nset_output_types(C(), {\"out\": int, \"extra\": bool})  # raises\n\n# after\nclass C:\n    @component.output_types(out=int, extra=bool)\n    def run(self, x: int):\n        return {\"out\": x, \"extra\": True}","handlingStrategy":"validation","validationCode":"def can_set_output_types(comp) -> bool:\n    return not hasattr(comp.run, \"_output_types_cache\") and not (\n        hasattr(comp, \"run_async\") and hasattr(comp.run_async, \"_output_types_cache\")\n    )","typeGuard":"def lacks_output_types_decorator(comp) -> bool:\n    run_async = getattr(comp, \"run_async\", None)\n    return (\n        not hasattr(comp.run, \"_output_types_cache\")\n        and (run_async is None or not hasattr(run_async, \"_output_types_cache\"))\n    )","tryCatchPattern":"try:\n    set_output_types(comp, {\"out\": int})\nexcept ComponentError as e:\n    logging.error(\"Remove @component.output_types decorator or the set_output_types call\")\n    raise","preventionTips":["Pick one output-declaration style per component: decorator OR set_output_types, never both","Check for the _output_types_cache attribute before calling set_output_types","When subclassing decorated components, do not re-declare outputs at runtime"],"tags":["python","haystack","component","sockets","output-types","conflict"],"backgroundTag":"output-types-declaration-conflict","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}