{"record":{"id":"b1866f44521fdf7e","repo":"langflow-ai/langflow","slug":"could-not-load-flow-module-flow-path","errorCode":null,"errorMessage":"Could not load flow module: {flow_path}","messagePattern":"Could not load flow module: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/agentic/services/helpers/flow_loader.py","lineNumber":137,"sourceCode":"\n    Args:\n        flow_path: Path to the Python flow file.\n        provider: Optional model provider (e.g., \"OpenAI\").\n        model_name: Optional model name (e.g., \"gpt-4o-mini\").\n        api_key_var: Optional API key variable name.\n        provider_vars: Resolved request variables; ``ITERATIONS_LIMIT`` is forwarded\n            to ``get_graph(iterations_limit=...)`` when the flow accepts it.\n\n    Returns:\n        Graph: The loaded and configured graph.\n\n    Raises:\n        HTTPException: If the flow file cannot be loaded or executed.\n    \"\"\"\n    module_name = flow_path.stem\n    spec = importlib.util.spec_from_file_location(module_name, flow_path)\n    if spec is None or spec.loader is None:\n        raise HTTPException(status_code=500, detail=f\"Could not load flow module: {flow_path}\")\n\n    module = importlib.util.module_from_spec(spec)\n    sys.modules[module_name] = module\n\n    try:\n        with _temporary_sys_path(str(flow_path.parent)):\n            spec.loader.exec_module(module)\n    except Exception as e:\n        if module_name in sys.modules:\n            del sys.modules[module_name]\n        logger.error(f\"Error loading Python flow module: {e}\")\n        raise HTTPException(status_code=500, detail=f\"Error loading flow module: {e}\") from e\n\n    if not hasattr(module, \"get_graph\"):\n        # Fallback: check for 'graph' variable for backward compatibility\n        if hasattr(module, \"graph\"):\n            graph = module.graph\n            validate_flow_for_current_settings(graph)","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/services/helpers/flow_loader.py#L119-L155","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import os, pathlib\n\ndef importable_py_flow(path: str) -> bool:\n    p = pathlib.Path(path)\n    return p.suffix == '.py' and p.is_file() and not p.is_dir() and os.access(p, os.R_OK)","typeGuard":null,"tryCatchPattern":"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.","preventionTips":["Avoid deleting/renaming flow files while requests are in flight (atomic rename deploys).","Never place directories named like '*.py' in the flows directory."],"tags":["agentic","flow-loader","import","http-500","python-flow"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}