langflow-ai/langflow · error · HTTPException
Flow module must define 'get_graph()' function: {flow_path}
Error message
Flow module must define 'get_graph()' function: {flow_path} What it means
Raised when flow_loader dynamically imports a Python flow module (.py file) but the module exposes neither a get_graph() function nor a module-level graph variable. Langflow requires one of these as the entry point to materialize a runnable graph. It surfaces as HTTPException 500 from the flow-loading endpoint.
Source
Thrown at src/backend/base/langflow/agentic/services/helpers/flow_loader.py:161
with _temporary_sys_path(str(flow_path.parent)):
spec.loader.exec_module(module)
except Exception as e:
if module_name in sys.modules:
del sys.modules[module_name]
logger.error(f"Error loading Python flow module: {e}")
raise HTTPException(status_code=500, detail=f"Error loading flow module: {e}") from e
if not hasattr(module, "get_graph"):
# Fallback: check for 'graph' variable for backward compatibility
if hasattr(module, "graph"):
graph = module.graph
validate_flow_for_current_settings(graph)
if module_name in sys.modules:
del sys.modules[module_name]
return graph
if module_name in sys.modules:
del sys.modules[module_name]
raise HTTPException(status_code=500, detail=f"Flow module must define 'get_graph()' function: {flow_path}")
get_graph_func = module.get_graph
# Build kwargs for get_graph based on what it accepts
sig = inspect.signature(get_graph_func)
kwargs = {}
if "provider" in sig.parameters and provider:
kwargs["provider"] = provider
if "model_name" in sig.parameters and model_name:
kwargs["model_name"] = model_name
if "api_key_var" in sig.parameters and api_key_var:
kwargs["api_key_var"] = api_key_var
# Python flows never pass through the JSON-side inject_iterations_into_flow,
# so the runtime step budget must be forwarded to get_graph explicitly.
raw_iterations = (provider_vars or {}).get("ITERATIONS_LIMIT")
if "iterations_limit" in sig.parameters and raw_iterations not in (None, ""):
with suppress(TypeError, ValueError):
kwargs["iterations_limit"] = int(raw_iterations)View on GitHub (pinned to 976ec789d2)
Solutions
- Add a module-level def get_graph() -> Graph: that builds and returns the flow's Graph object.
- Alternatively define a module-level graph variable for backward compatibility (the loader accepts it as a fallback).
- Check for a typo: the loader matches the exact names 'get_graph' and 'graph'.
- Verify you pointed flow_path at the entry file of the flow, not a helper module.
Example fix
# before
# my_flow.py
def build_graph():
return Graph(...)
# after
# my_flow.py
def get_graph():
return Graph(...) Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
def flow_module_is_loadable(flow_path: str) -> bool:
spec = importlib.util.spec_from_file_location("_probe", flow_path)
if spec is None or spec.loader is None:
return False
mod = importlib.util.module_from_spec(spec)
try:
spec.loader.exec_module(mod)
except Exception:
return False
return hasattr(mod, "get_graph") or hasattr(mod, "graph") Type guard
def has_graph_entrypoint(module) -> TypeGuard[Any]:
return hasattr(module, "get_graph") or hasattr(module, "graph") Try / catch
try:
graph = load_flow_module(flow_path)
except HTTPException as e:
if "must define 'get_graph()'" in e.detail:
raise ValueError(f"{flow_path} lacks get_graph()/graph") from e
raise Prevention
- Standardize every Python flow on a module-level get_graph() factory.
- Lint flow files in CI with a check that the module exposes get_graph or graph.
- Never rename the factory without a loader-compatibility shim (keep a graph variable fallback).
When it happens
Trigger: Calling the agentic flow-loader endpoint with a flow_path pointing at a Python file whose module defines neither 'get_graph' nor 'graph' (e.g. only helper functions, or the graph factory is named differently like build_graph()). The module is imported, inspected with hasattr for both symbols, and rejected when both checks fail.
Common situations: Migrating flows written for an older loader that expected a different factory name; typos in the function name (getGraph, get_graph_async); a module that conditionally defines get_graph only under __main__; picking the wrong file out of a multi-file flow project.
Related errors
- Error creating graph: {e}
- Invalid flow filename
- Invalid flow filename: '{flow_filename}'
- Flow file '{flow_filename}' not found
- Could not load flow module: {flow_path}
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/e4522b0f659d2d4f.
Report an issue: GitHub.