{"record":{"id":"a1d707cb09029ce7","repo":"invoke-ai/InvokeAI","slug":"duplicate-workflow-return-key-key","errorCode":null,"errorMessage":"Duplicate workflow return key '{key}'.","messagePattern":"Duplicate workflow return key '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/workflow_return.py","lineNumber":100,"sourceCode":"class WorkflowReturnInvocation(BaseInvocation):\n    \"\"\"Defines the explicit named result returned by a callable workflow.\"\"\"\n\n    values: WorkflowReturnValueField | list[WorkflowReturnValueField] = InputField(\n        default=[],\n        description=\"The named values returned to a calling workflow.\",\n        title=\"Values\",\n        input=Input.Connection,\n    )\n\n    def invoke(self, context: InvocationContext) -> WorkflowReturnOutput:\n        named_values: dict[str, Any] = {}\n        return_values = self.values if isinstance(self.values, list) else [self.values]\n        for value in return_values:\n            key = value.key.strip()\n            if not key:\n                raise ValueError(\"Workflow return key must not be empty.\")\n            if key in named_values:\n                raise ValueError(f\"Duplicate workflow return key '{key}'.\")\n            named_values[key] = value.value\n        return WorkflowReturnOutput(values=named_values)\n\n\n@invocation_output(\"workflow_return_get_output\")\nclass WorkflowReturnGetOutput(BaseInvocationOutput):\n    \"\"\"A value extracted from named workflow return values.\"\"\"\n\n    value: Any = OutputField(description=\"The extracted workflow return value.\", title=\"Value\", ui_type=UIType.Any)\n\n\n@invocation(\n    \"workflow_return_get\",\n    title=\"Get Workflow Return Value\",\n    tags=[\"workflow\", \"return\", \"input\"],\n    category=\"workflow\",\n    version=\"1.0.0\",\n    classification=Classification.Beta,","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/workflow_return.py#L82-L118","documentation":"The Workflow Return invocation collects named return values into a dict keyed by each value's 'key'. If two entries have the same (whitespace-stripped) key, the later value would silently overwrite the earlier one, so the library raises ValueError to force unique keys. This protects downstream Workflow Get invocations from resolving to the wrong value.","triggerScenarios":"A workflow-return invocation whose 'values' list contains two WorkflowReturnValue entries with identical 'key' strings (after stripping whitespace); invoke() iterates the list and raises on the second occurrence.","commonSituations":"Duplicating a return node in the workflow editor and forgetting to rename the key; copying a node whose key field was copied verbatim; programmatic workflow JSON generation emitting the same key twice.","solutions":["Open the workflow-return invocation and give each value a unique 'key' string","Strip/normalize keys in your workflow JSON to confirm the collision (keys differing only by surrounding whitespace still collide)","If two outputs genuinely share a name, nest them under distinct prefixes, e.g. 'image1' and 'image2'","Re-export/validate the workflow JSON programmatically to detect duplicates before running"],"exampleFix":"// before\nvalues = [\n  WorkflowReturnValue(key='image', value=img1),\n  WorkflowReturnValue(key='image', value=img2),\n]\n// after\nvalues = [\n  WorkflowReturnValue(key='image_primary', value=img1),\n  WorkflowReturnValue(key='image_secondary', value=img2),\n]","handlingStrategy":"validation","validationCode":"def validate_return_keys(values):\n    keys = [v.key.strip() for v in (values if isinstance(values, list) else [values])]\n    dupes = {k for k in keys if keys.count(k) > 1}\n    if dupes:\n        raise ValueError(f\"Duplicate workflow return keys: {sorted(dupes)}\")\n    if \"\" in keys:\n        raise ValueError(\"Workflow return key must not be empty.\")","typeGuard":null,"tryCatchPattern":"try:\n    output = invocation.invoke(context)\nexcept ValueError as e:\n    if \"Duplicate workflow return key\" in str(e):\n        fix_duplicate_keys(workflow)\n    else:\n        raise","preventionTips":["Give each return value a distinct, descriptive key at authoring time","Run a pre-execution lint of workflow JSON for duplicate keys","Avoid copying return nodes without renaming their keys"],"tags":["workflow","validation","duplicate-key"],"backgroundTag":"duplicate-key-validation","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}