deepset-ai/haystack · error · PipelineConnectError

Connecting a Component to itself is not supported.

Error message

Connecting a Component to itself is not supported.

What it means

Pipeline edges connect two distinct components. connect(sender, receiver) rejects calls where both strings refer to the same component, since a self-loop has no meaningful input/output socket pairing, raising PipelineConnectError.

Source

Thrown at haystack/core/pipeline/base.py:620

            The component that delivers the value. This can be either just a component name or can be
            in the format `component_name.connection_name` if the component has multiple outputs.
        :param receiver:
            The component that receives the value. This can be either just a component name or can be
            in the format `component_name.connection_name` if the component has multiple inputs.

        :returns:
            The Pipeline instance.

        :raises PipelineConnectError:
            If the two components cannot be connected (for example if one of the components is
            not present in the pipeline, or the connections don't match by type, and so on).
        """
        # Edges may be named explicitly by passing 'node_name.edge_name' to connect().
        sender_component_name, sender_socket_name = parse_connect_string(sender)
        receiver_component_name, receiver_socket_name = parse_connect_string(receiver)

        if sender_component_name == receiver_component_name:
            raise PipelineConnectError("Connecting a Component to itself is not supported.")

        # Get the nodes data.
        try:
            sender_sockets = self.graph.nodes[sender_component_name]["output_sockets"]
        except KeyError as exc:
            raise ValueError(f"Component named {sender_component_name} not found in the pipeline.") from exc
        try:
            receiver_sockets = self.graph.nodes[receiver_component_name]["input_sockets"]
        except KeyError as exc:
            raise ValueError(f"Component named {receiver_component_name} not found in the pipeline.") from exc

        if not sender_sockets:
            raise PipelineConnectError(
                f"'{sender_component_name}' does not have any output connections. "
                f"Please check that the output types of '{sender_component_name}.run' are set, "
                f"for example by using the '@component.output_types' decorator."
            )

View on GitHub (pinned to e318778c9b)

Solutions

  1. Connect the component to a different component, or insert an intermediary component between them
  2. If self-processing is intended, do it inside the component's run() rather than via an edge
  3. Assert sender != receiver in code that generates connections dynamically

Example fix

// before
pipe.connect("prompt_builder", "prompt_builder")
// after
pipe.connect("prompt_builder", "llm")
Defensive patterns

Strategy: validation

Validate before calling

def is_valid_edge(pipe, sender: str, receiver: str) -> bool:
    s = sender.split(".")[0]
    r = receiver.split(".")[0]
    return s != r and s in pipe.graph.nodes and r in pipe.graph.nodes

Type guard

def is_self_loop(sender: str, receiver: str) -> bool:
    return sender.split(".")[0] == receiver.split(".")[0]

Try / catch

from haystack.core.errors import PipelineConnectError
try:
    pipe.connect(sender, receiver)
except PipelineConnectError as e:
    if "to itself" in str(e):
        logger.warning("Skipped self-connection %s -> %s", sender, receiver)
    else:
        raise

Prevention

When it happens

Trigger: pipe.connect("prompt", "prompt"); programmatically building edge lists where sender and receiver variables end up equal; templated generation that did not check name inequality.

Common situations: Auto-wiring loops over component names with an off-by-one or identity pairing; copy-paste of connect lines with the wrong receiver edited.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/ab4b854135ad1d1e. Report an issue: GitHub.