Exception types raised during graph construction and execution
Hypergraph defines specific exception types for different error conditions. All exceptions are exported from the main package and can be caught for error handling.
Raised when a graph with cycles exceeds the max_iterations limit without reaching a stable state or END sentinel.
from hypergraph import InfiniteLoopErrortry: result = runner.run(graph, {"query": "hello"}, max_iterations=10)except InfiniteLoopError as e: print(f"Exceeded {e.max_iterations} iterations") # The graph may have an infinite loop
Raised during graph construction when there are configuration issues like invalid routing targets, name conflicts, or type mismatches with strict_types=True.
from hypergraph import GraphConfigError, route, END@route(targets=["step_a", "step_b", END])def decide(x: int) -> str: return "step_c" # Typo - not in targets!try: graph = Graph([decide, step_a, step_b])except GraphConfigError as e: print(e) # Route target 'step_c' not found in node 'decide' # Valid targets: ['step_a', 'step_b', 'END'] # Did you mean 'step_a'?
When raised:
Route targets reference non-existent nodes
Type mismatch with strict_types=True
Name conflicts between nodes
Invalid graph configuration
Build-time validation: This error occurs when constructing the Graph, not at runtime, so you catch errors early.
Raised when a rename operation (with_inputs, with_outputs, with_name) references a non-existent parameter name.
from hypergraph import RenameError, node@node(output_name="result")def process(x: int) -> int: return x * 2try: # Try to rename non-existent parameter renamed = process.with_inputs(y="input")except RenameError as e: print(e) # 'y' not found. Current inputs: ('x',)
The error message includes rename history context:
renamed = process.with_inputs(x="value")try: # 'x' was already renamed to 'value' renamed.with_inputs(x="different")except RenameError as e: print(e) # 'x' was renamed to 'value'. Current inputs: ('value',)
When raised:
Attempting to rename an input/output that doesn’t exist
Attempting to use the old name after renaming
How to avoid:
Check node.inputs and node.outputs before renaming