langflow-ai/langflow · error · HTTPException
Could not load flow module: {flow_path}
Error message
Could not load flow module: {flow_path} What it means
Raised when importlib.util.spec_from_file_location returns None (or a spec without a loader) for a .py flow file. This means Python's import machinery could not create a loader for the path at all — classically because the file extension is not importable or the path is not a regular file. HTTP 500 with the offending path echoed.
Source
Thrown at src/backend/base/langflow/agentic/services/helpers/flow_loader.py:137
Args:
flow_path: Path to the Python flow file.
provider: Optional model provider (e.g., "OpenAI").
model_name: Optional model name (e.g., "gpt-4o-mini").
api_key_var: Optional API key variable name.
provider_vars: Resolved request variables; ``ITERATIONS_LIMIT`` is forwarded
to ``get_graph(iterations_limit=...)`` when the flow accepts it.
Returns:
Graph: The loaded and configured graph.
Raises:
HTTPException: If the flow file cannot be loaded or executed.
"""
module_name = flow_path.stem
spec = importlib.util.spec_from_file_location(module_name, flow_path)
if spec is None or spec.loader is None:
raise HTTPException(status_code=500, detail=f"Could not load flow module: {flow_path}")
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
try:
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)View on GitHub (pinned to 976ec789d2)
Solutions
- Verify FLOWS_BASE_PATH/<name> is a regular file (not a directory) and still exists at call time.
- Redeploy the flow file if it was removed; avoid deleting files while requests are in flight (write-then-rename deployments).
- If it recurs, inspect the path in the error detail against the actual filesystem layout.
Defensive patterns
Strategy: validation
Validate before calling
import os, pathlib
def importable_py_flow(path: str) -> bool:
p = pathlib.Path(path)
return p.suffix == '.py' and p.is_file() and not p.is_dir() and os.access(p, os.R_OK) Try / catch
On 500 'Could not load flow module', verify the path from the detail is a regular file, redeploy if it vanished, and retry once after confirmation.
Prevention
- Avoid deleting/renaming flow files while requests are in flight (atomic rename deploys).
- Never place directories named like '*.py' in the flows directory.
When it happens
Trigger: A flow resolved to a .py path that reached _load_graph_from_python but whose path cannot yield an import spec — e.g. a file with a .py name that is actually a directory, a dangling state after the file was deleted between resolve and import, or an exotic filesystem where FileLoader is unavailable.
Common situations: Race with a deploy job deleting/renaming files mid-request; a directory accidentally named 'flow.py' inside the flows folder; unusual mounts (some network filesystems) confusing the loader.
Related errors
- Error loading flow module: {e}
- An error occurred while executing the flow.
- An internal error occurred while executing the flow.
- An error occurred while preparing the flow.
- Invalid flow filename
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/b1866f44521fdf7e.
Report an issue: GitHub.