{"record":{"id":"e8277cd39a369ebe","repo":"langflow-ai/langflow","slug":"error-creating-graph-e","errorCode":null,"errorMessage":"Error creating graph: {e}","messagePattern":"Error creating graph: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/agentic/services/helpers/flow_loader.py","lineNumber":202,"sourceCode":"    # to every tool. Any later deepcopy/pickle of those tools triggers\n    # LangfuseResourceManager.__new__() with no kwargs and raises. Tracing belongs\n    # to flow execution, not graph assembly, so we clear it for the duration.\n    trace_token = None\n    try:\n        from langflow.services.tracing.service import trace_context_var\n\n        trace_token = trace_context_var.set(None)\n    except ImportError:\n        trace_token = None\n\n    try:\n        if inspect.iscoroutinefunction(get_graph_func):\n            graph = await get_graph_func(**kwargs)\n        else:\n            graph = get_graph_func(**kwargs)\n    except Exception as e:\n        logger.exception(f\"Error executing get_graph(): {e}\")\n        raise HTTPException(status_code=500, detail=f\"Error creating graph: {e}\") from e\n    finally:\n        if trace_token is not None:\n            from langflow.services.tracing.service import trace_context_var\n\n            trace_context_var.reset(trace_token)\n        if module_name in sys.modules:\n            del sys.modules[module_name]\n\n    validate_flow_for_current_settings(graph)\n    return graph\n\n\nasync def load_graph_for_execution(\n    flow_path: Path,\n    flow_type: str,\n    provider: str | None = None,\n    model_name: str | None = None,\n    api_key_var: str | None = None,","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/agentic/services/helpers/flow_loader.py#L184-L220","documentation":"Raised when the flow module's get_graph() function itself throws during execution (sync or async). The loader logs the full traceback via logger.exception and wraps the original exception in HTTPException 500 with detail 'Error creating graph: {e}'. The finally block still cleans up the trace context and removes the module from sys.modules, so retrying re-imports fresh.","triggerScenarios":"flow_path resolves to a valid module with get_graph, but calling it raises: missing API key env var, invalid model name passed via kwargs (provider/model_name/api_key_var are forwarded when the signature accepts them), a component constructor failing, or an import error triggered lazily inside the factory.","commonSituations":"Provider/model_name arguments mismatched with what the flow expects; expired or unset credentials the graph builder reads at build time; code that works in a notebook but depends on cwd-relative paths; component version changes after a Langflow upgrade.","solutions":["Read the server logs — logger.exception records the full traceback of the underlying error; fix the root cause shown there.","Run the module standalone (python -c \"import my_flow; my_flow.get_graph()\") to reproduce the failure outside the loader.","If provider/model_name/api_key_var are being injected, make sure the graph factory accepts and uses them correctly.","Check that all dependencies imported inside get_graph are installed in the backend environment."],"exampleFix":"# before\ndef get_graph():\n    return Graph(openai_api_key=os.environ[\"OPENAI_API_KEY\"])  # KeyError -> 500\n\n# after\ndef get_graph(api_key_var: str | None = None):\n    key = os.environ.get(api_key_var or \"OPENAI_API_KEY\", \"\")\n    return Graph(openai_api_key=key)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    graph = await load_flow_graph(flow_path, provider=provider, model_name=model_name)\nexcept HTTPException as e:\n    log.exception(\"get_graph failed for %s\", flow_path)  # server log has the real traceback\n    raise","preventionTips":["Smoke-test get_graph() in CI for every committed flow module.","Read env vars with os.environ.get and explicit error messages instead of letting KeyError escape.","Pin provider/model_name values the flow factory actually supports."],"tags":["flow-loader","get-graph","runtime-error","http-500"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}