{"record":{"id":"ce3eafc33aacc590","repo":"invoke-ai/InvokeAI","slug":"a-workflow-may-not-contain-more-than-one-workflow","errorCode":null,"errorMessage":"A workflow may not contain more than one workflow_return node.","messagePattern":"A workflow may not contain more than one workflow_return node\\.","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"invokeai/app/services/workflow_records/workflow_records_common.py","lineNumber":90,"sourceCode":"    # it is None.\n    form: dict[str, JsonValue] | None = Field(default=None, description=\"The form of the workflow.\")\n\n    model_config = ConfigDict(extra=\"ignore\")\n\n    @field_validator(\"nodes\")\n    @classmethod\n    def validate_workflow_return_node_uniqueness(cls, nodes: list[dict[str, JsonValue]]):\n        workflow_return_count = 0\n\n        for node in nodes:\n            if not isinstance(node, dict) or node.get(\"type\") != \"invocation\":\n                continue\n            data = node.get(\"data\")\n            if isinstance(data, dict) and data.get(\"type\") == \"workflow_return\":\n                workflow_return_count += 1\n\n        if workflow_return_count > 1:\n            raise ValueError(\"A workflow may not contain more than one workflow_return node.\")\n\n        return nodes\n\n\nWorkflowWithoutIDValidator = TypeAdapter(WorkflowWithoutID)\n\n\nclass UnsafeWorkflowWithVersion(BaseModel):\n    \"\"\"\n    This utility model only requires a workflow to have a valid version string.\n    It is used to validate a workflow version without having to validate the entire workflow.\n    \"\"\"\n\n    meta: WorkflowMeta = Field(description=\"The meta of the workflow.\")\n\n\nUnsafeWorkflowWithVersionValidator = TypeAdapter(UnsafeWorkflowWithVersion)\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/workflow_records/workflow_records_common.py#L72-L108","documentation":"Workflow validation enforces that at most one node of type 'workflow_return' exists in a workflow. Multiple return nodes are ambiguous (which result should the workflow produce?), so the validator raises ValueError while parsing the nodes list.","triggerScenarios":"Loading or saving a WorkflowWithoutID/Workflow whose nodes contain two or more nodes with data.type == 'workflow_return'.","commonSituations":"Duplicating a node in the editor without deleting the original, merging two workflow JSON files, programmatic workflow generation that appends a return node per output.","solutions":["Remove the duplicate workflow_return node(s), keeping exactly one","Re-wire the second return's inputs into the single return node if both outputs are needed","Fix generator/merge code so it reuses one return node instead of appending new ones"],"exampleFix":"// before\nnodes = [n1, return_node_a, return_node_b]\n// after\nnodes = [n1, return_node_a]  # delete or merge return_node_b","handlingStrategy":"validation","validationCode":"def count_return_nodes(nodes: list[dict]) -> int:\n    return sum(1 for n in nodes\n               if isinstance(n.get(\"data\"), dict) and n[\"data\"].get(\"type\") == \"workflow_return\")\nassert count_return_nodes(workflow_dict[\"nodes\"]) <= 1","typeGuard":"def has_single_return(nodes: object) -> bool:\n    return isinstance(nodes, list) and count_return_nodes(nodes) == 1","tryCatchPattern":"try:\n    wf = WorkflowWithoutID.model_validate(data)\nexcept ValueError as e:\n    if \"workflow_return\" in str(e):\n        data[\"nodes\"] = [n for n in data[\"nodes\"] if not (isinstance(n.get(\"data\"), dict) and n[\"data\"].get(\"type\") == \"workflow_return\")][:0] or dedupe_returns(data[\"nodes\"])\n        wf = WorkflowWithoutID.model_validate(data)\n    else:\n        raise","preventionTips":["When duplicating nodes in generated workflows, special-case workflow_return","Run validation on merged workflow JSON before saving","Keep a single template return node and rewire inputs instead of adding new ones"],"tags":["workflow","validation","pydantic"],"backgroundTag":"schema-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}