langgenius/dify · error · ValueError

Workflow not initialized

Error message

Workflow not initialized

What it means

Bare ValueError('Workflow not initialized') raised inside DraftWorkflowNodeRunApi.post (POST /apps/{app_id}/workflows/draft/nodes/{node_id}/run) when WorkflowService.get_draft_workflow returns None for the app. This means the app has no saved draft workflow graph yet, so no node can be run. The ValueError propagates uncaught and is returned as HTTP 400 'Workflow not initialized'.

Source

Thrown at api/controllers/console/app/workflow.py:1236

    @get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
    @with_current_user
    @edit_permission_required
    def post(self, current_user: Account, app_model: App, node_id: str):
        """
        Run draft workflow node
        """
        args_model = DraftWorkflowNodeRunPayload.model_validate(console_ns.payload or {})
        args = args_model.model_dump(exclude_none=True)

        user_inputs = args_model.inputs
        if user_inputs is None:
            raise ValueError("missing inputs")

        workflow_srv = WorkflowService()
        # fetch draft workflow by app_model
        draft_workflow = workflow_srv.get_draft_workflow(app_model=app_model, session=db.session())
        if not draft_workflow:
            raise ValueError("Workflow not initialized")
        files = _parse_file(draft_workflow, args.get("files"))
        workflow_service = WorkflowService()

        workflow_node_execution = workflow_service.run_draft_workflow_node(
            app_model=app_model,
            draft_workflow=draft_workflow,
            node_id=node_id,
            user_inputs=user_inputs,
            account=current_user,
            query=args.get("query", ""),
            files=files,
        )

        return WorkflowRunNodeExecutionResponse.model_validate(
            workflow_node_execution, from_attributes=True
        ).model_dump(mode="json")

View on GitHub (pinned to ef8544b173)

Solutions

  1. Open the workflow editor and save the draft at least once before running a node.
  2. Verify the app is in WORKFLOW or ADVANCED_CHAT mode and has a draft workflow row.
  3. If the draft was deleted, recreate it by saving the graph in the editor.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm a draft workflow exists before allowing node-run.
const draft = await getDraftWorkflow(appId);
if (!draft) { notifyUser('Save the workflow first'); return; }

Type guard

const hasDraft = (d): d is {id: string} => !!d && typeof d.id === 'string';

Try / catch

try {
  return await runDraftNode(appId, nodeId, body);
} catch (e) {
  if (e?.status === 400 && /Workflow not initialized/i.test(e?.message)) {
    promptSaveWorkflow(); return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the node-run endpoint on an app that has never had its workflow draft persisted (e.g. a freshly created app before any save), or whose draft was deleted.

Common situations: New workflow/advanced-chat app whose graph was never saved; the user opened the editor but never triggered an autosave/publish; data inconsistency after migration.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/e97b1f9c0f297d4d. Report an issue: GitHub.