invoke-ai/InvokeAI · error · InvalidEdgeError

Edge source and target types do not match ({edge})

Error message

Edge source and target types do not match ({edge})

What it means

InvalidEdgeError raised when validating a graph whose existing edge connects fields whose output/input types fail are_connections_compatible(). It guards the whole stored edge set in validate_self(), distinct from the per-edge add-path check (_validate_edge_field_compatibility). Ensures no edge carries data of the wrong type between nodes.

Source

Thrown at invokeai/app/services/shared/graph.py:1848

    def _validate_graph_is_acyclic(self) -> None:
        graph = self.nx_graph_flat()
        if not nx.is_directed_acyclic_graph(graph):
            raise CyclicalGraphError("Graph contains cycles")

    def _validate_edge_type_compatibility(self) -> None:
        for edge in self.edges:
            destination_node = self.get_node(edge.destination.node_id)
            if isinstance(destination_node, CallSavedWorkflowInvocation) and is_call_saved_workflow_dynamic_input(
                edge.destination.field
            ):
                continue
            if not are_connections_compatible(
                self.get_node(edge.source.node_id),
                edge.source.field,
                destination_node,
                edge.destination.field,
            ):
                raise InvalidEdgeError(f"Edge source and target types do not match ({edge})")

    def _validate_special_nodes(self) -> None:
        # TODO: may need to validate all iterators & collectors in subgraphs so edge connections in parent graphs will be available
        for node in self.nodes.values():
            if isinstance(node, IterateInvocation):
                err = self._is_iterator_connection_valid(node.id)
                if err is not None:
                    raise InvalidEdgeError(f"Invalid iterator node ({node.id}): {err}")
            if isinstance(node, CollectInvocation):
                err = self._is_collector_connection_valid(node.id)
                if err is not None:
                    raise InvalidEdgeError(f"Invalid collector node ({node.id}): {err}")

    def validate_self(self) -> None:
        """
        Validates the graph.

        Raises an exception if the graph is invalid:

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Identify the failing edge from the message (it includes the edge object)
  2. Check get_output_field_type of the source field vs get_input_field_type of the destination field
  3. Insert a type-conversion node between the two nodes or connect to a matching-typed field
  4. Re-open and fix the workflow in the UI, which enforces type compatibility on connect
  5. Pin or update the custom node pack that changed the field type

Example fix

// before
g.add_edge(load_image, "image", save_latents, "latents")  # type mismatch
// after
g.add_edge(load_image, "image", resize_image, "image")
g.add_edge(vae_encode, "latents", save_latents, "latents")
Defensive patterns

Strategy: validation

Validate before calling

from invokeai.app.services.shared.graph import are_connections_compatible

def edge_types_ok(graph, edge):
    return are_connections_compatible(
        graph.get_node(edge.source.node_id), edge.source.field,
        graph.get_node(edge.destination.node_id), edge.destination.field,
    )

assert all(edge_types_ok(g, e) for e in g.edges)

Type guard

def edge_is_typed(graph, edge) -> bool:
    try:
        return are_connections_compatible(
            graph.get_node(edge.source.node_id), edge.source.field,
            graph.get_node(edge.destination.node_id), edge.destination.field,
        )
    except NodeNotFoundError:
        return False

Try / catch

from invokeai.app.services.shared.graph import InvalidEdgeError

try:
    graph.validate_self()
except InvalidEdgeError as e:
    logger.error("bad edge: %s", e)
    # remove/redirect the offending edge named in the message

Prevention

When it happens

Trigger: validate_self() iterating self.edges where any edge's source field output type mismatches the destination field's input type, typically after node field definitions changed or the graph was hand-constructed/edited.

Common situations: Custom node packs updated and changed a field type (e.g. image -> latents), workflows edited by hand in JSON, connecting a string field to an image field via a script.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/1c505f6b6cc8b676. Report an issue: GitHub.