{"record":{"id":"5940f02d93af6abd","repo":"HumanSignal/label-studio","slug":"undefined-expression-you-can-use-add-data-field","errorCode":null,"errorMessage":"Undefined expression, you can use: {add_data_field_examples}","messagePattern":"Undefined expression, you can use: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":314,"sourceCode":"\n    elif command == 'random':\n        if len(args) != 2:\n            raise ValidationError({'value': 'random(min, max) requires two arguments.'})\n        minimum, maximum = int(args[0]), int(args[1])\n\n    elif command == 'choices':\n        if not 0 < len(args) < 3:\n            raise ValidationError({'value': 'choices(values:list, weights:list) requires one or two arguments.'})\n        weights = json.loads(args[1]) if len(args) == 2 else None\n        choices = json.loads(args[0])\n\n    elif command == 'replace':\n        if len(args) != 2:\n            raise ValidationError({'value': 'replace(old_value, new_value) requires two arguments.'})\n        old_value, new_value = json.loads(args[0]), json.loads(args[1])\n\n    else:\n        raise ValidationError('Undefined expression, you can use: ' + add_data_field_examples)\n\n    offset = 0\n    task_iterator = iterate_queryset(queryset.only('id', 'data'), chunk_size=settings.UPDATE_COLUMN_BATCH_SIZE)\n    for task_batch in batched_iterator(task_iterator, settings.UPDATE_COLUMN_BATCH_SIZE):\n        if command == 'range':\n            for index, task in enumerate(task_batch):\n                task.data[value_name] = start + offset + index\n        elif command == 'sample':\n            for task in task_batch:\n                task.data[value_name] = next(sample_values)\n        elif command == 'random':\n            for task in task_batch:\n                task.data[value_name] = random.randint(minimum, maximum)\n        elif command == 'choices':\n            for task, selected_value in zip(\n                task_batch, random.choices(population=choices, weights=weights, k=len(task_batch))\n            ):\n                task.data[value_name] = selected_value","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L296-L332","documentation":"The add_expression dispatcher only knows the commands range, sample, random, choices, and replace; anything else falls into the else branch and raises this ValidationError listing the supported examples. It is the fallback for unrecognized/misspelled expression commands in add/update-column actions.","triggerScenarios":"Calling the add-data-field action with an unknown command such as {\"command\": \"shuffle\"}, a typo like \"sampl\", or uppercase \"Random\"; sending an empty/missing command field.","commonSituations":"Typos in command names; inventing expressions that exist in other tools but not Label Studio; version drift where a client uses a command from a forked/newer backend; case-sensitivity mistakes.","solutions":["Use one of the supported commands exactly: range, sample, random, choices, replace (all lowercase)","Check the API response message, which appends add_data_field_examples listing valid expressions","If you need other mutations, perform them in your own preprocessing before uploading tasks instead of via this action"],"exampleFix":"// before\n{\"command\": \"shuffle\", \"args\": []}\n// after\n{\"command\": \"sample\", \"args\": []}","handlingStrategy":"validation","validationCode":"const ALLOWED = ['range', 'sample', 'random', 'choices', 'replace'];\nif (!ALLOWED.includes(expr.command)) {\n  throw new Error(`Unknown expression command: ${expr.command}`);\n}","typeGuard":"function isKnownCommand(e) { return ['range','sample','random','choices','replace'].includes(e?.command); }","tryCatchPattern":"try {\n  await dm.addAction({id: 'add_data_field', expression: expr});\n} catch (e) {\n  if (String(e).startsWith('Undefined expression')) {\n    showSupportedCommandsUI();\n  } else throw e;\n}","preventionTips":["Restrict command selection to a fixed lowercase enum in the UI","Check the supported examples list in the backend error message","Guard against version drift: confirm commands against the deployed backend version"],"tags":["label-studio","data-manager","validation","api"],"backgroundTag":"unknown-command","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}