{"record":{"id":"2d79511af5d0e46f","repo":"HumanSignal/label-studio","slug":"sample-does-not-accept-arguments","errorCode":null,"errorMessage":"sample() does not accept arguments.","messagePattern":"sample\\(\\) does not accept arguments\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":294,"sourceCode":"    command, args = value.split('(', 1)\n    if not command:\n        raise ValidationError({'value': 'Expression command is required.'})\n    args = process_arrays(args)\n    args = args.replace(')', '').split(',')\n    args = [] if len(args) == 1 and args[0] == '' else args\n    for i, arg in enumerate(args):\n        args[i] = arg.replace(';', ',').replace(\"'\", '\"')\n\n    sample_values = None\n\n    if command == 'range':\n        if len(args) != 1:\n            raise ValidationError({'value': 'range(start:int) requires one start argument.'})\n        start = int(args[0])\n\n    elif command == 'sample':\n        if args:\n            raise ValidationError({'value': 'sample() does not accept arguments.'})\n        sample_values = iter(random.sample(range(0, size), size))\n\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","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L276-L312","documentation":"The DataManager 'sample' expression generates random row values for an add/update-column action. It is deliberately argument-free: sample() fills the new column with random values drawn from range(0, size). Passing any arguments to sample() raises this ValidationError in add_expression before any tasks are processed.","triggerScenarios":"Calling the add-data-field action with expression {\"command\": \"sample\", \"args\": [\"100\"]} or any non-empty args list; POSTing the mutation payload via _stage_column_mutation / _apply_column_mutation with extra parameters after the sample command.","commonSituations":"Developers confuse sample() with random(min, max) or range(start) and pass a count argument expecting sample(n); copy-pasted payloads from other commands; UI clients that always serialize an args array.","solutions":["Remove all entries from the args array so the sample expression payload has \"args\": []","If you intended bounded random values, use the random command with exactly two args: random(min, max)","If you intended sequential values, use range(start) with one argument"],"exampleFix":"// before\n{\"command\": \"sample\", \"args\": [\"100\"]}\n// after\n{\"command\": \"sample\", \"args\": []}","handlingStrategy":"validation","validationCode":"if (expr.command === 'sample' && Array.isArray(expr.args) && expr.args.length > 0) {\n  throw new Error('sample() takes no arguments');\n}","typeGuard":"function isValidSample(e) { return e.command === 'sample' && (!e.args || e.args.length === 0); }","tryCatchPattern":"try {\n  await dm.addAction({id: 'add_data_field', expression: expr});\n} catch (e) {\n  if (String(e).includes('sample() does not accept arguments')) fixArgs(expr);\n  else throw e;\n}","preventionTips":["Build expression payloads from a schema/enum per command instead of hand-writing args","Remember sample() is argument-free; bounds belong to random(min,max)","Add client-side arg-count checks matching the backend for each command"],"tags":["label-studio","data-manager","validation","api"],"backgroundTag":"invalid-arguments","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}