langflow-ai/langflow · error · HTTPException
Error creating graph: {e}
Error message
Error creating graph: {e} What it means
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.
Source
Thrown at src/backend/base/langflow/agentic/services/helpers/flow_loader.py:202
# to every tool. Any later deepcopy/pickle of those tools triggers
# LangfuseResourceManager.__new__() with no kwargs and raises. Tracing belongs
# to flow execution, not graph assembly, so we clear it for the duration.
trace_token = None
try:
from langflow.services.tracing.service import trace_context_var
trace_token = trace_context_var.set(None)
except ImportError:
trace_token = None
try:
if inspect.iscoroutinefunction(get_graph_func):
graph = await get_graph_func(**kwargs)
else:
graph = get_graph_func(**kwargs)
except Exception as e:
logger.exception(f"Error executing get_graph(): {e}")
raise HTTPException(status_code=500, detail=f"Error creating graph: {e}") from e
finally:
if trace_token is not None:
from langflow.services.tracing.service import trace_context_var
trace_context_var.reset(trace_token)
if module_name in sys.modules:
del sys.modules[module_name]
validate_flow_for_current_settings(graph)
return graph
async def load_graph_for_execution(
flow_path: Path,
flow_type: str,
provider: str | None = None,
model_name: str | None = None,
api_key_var: str | None = None,View on GitHub (pinned to 976ec789d2)
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.
Example fix
# before
def get_graph():
return Graph(openai_api_key=os.environ["OPENAI_API_KEY"]) # KeyError -> 500
# after
def get_graph(api_key_var: str | None = None):
key = os.environ.get(api_key_var or "OPENAI_API_KEY", "")
return Graph(openai_api_key=key) Defensive patterns
Strategy: try-catch
Try / catch
try:
graph = await load_flow_graph(flow_path, provider=provider, model_name=model_name)
except HTTPException as e:
log.exception("get_graph failed for %s", flow_path) # server log has the real traceback
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not load flow module: {flow_path}
- Error loading flow module: {e}
- Flow module must define 'get_graph()' function: {flow_path}
- parse_exception(exc)
- parse_exception(exc)
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/e8277cd39a369ebe.
Report an issue: GitHub.