{"record":{"id":"c6342ae754edeb96","repo":"HumanSignal/label-studio","slug":"random-min-max-requires-two-arguments","errorCode":null,"errorMessage":"random(min, max) requires two arguments.","messagePattern":"random\\(min, max\\) requires two arguments\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":299,"sourceCode":"    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\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)","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L281-L317","documentation":"The DataManager 'random' expression fills a column with random integers in [min, max]. add_expression enforces exactly two arguments and raises this ValidationError when len(args) != 2 (zero, one, or three-plus arguments).","triggerScenarios":"Calling the add-data-field action with {\"command\": \"random\", \"args\": []}, {\"command\": \"random\", \"args\": [\"10\"]}, or {\"command\": \"random\", \"args\": [\"1\",\"10\",\"5\"]} via the column mutation action.","commonSituations":"Developers assume random() needs no bounds (like Python's random.random), or supply min only expecting max defaults; UI form that sends empty strings for unset bounds.","solutions":["Supply exactly two arguments: {\"command\": \"random\", \"args\": [\"1\", \"100\"]} for min and max","Ensure both values are integers (they are passed through int(args[i]))","If no bounds are desired, use sample() with no args or range(start) instead"],"exampleFix":"// before\n{\"command\": \"random\", \"args\": [\"10\"]}\n// after\n{\"command\": \"random\", \"args\": [\"0\", \"10\"]}","handlingStrategy":"validation","validationCode":"if (expr.command === 'random' && (!Array.isArray(expr.args) || expr.args.length !== 2)) {\n  throw new Error('random requires exactly [min, max]');\n}","typeGuard":"function isValidRandom(e) { return e.command === 'random' && Array.isArray(e.args) && e.args.length === 2 && e.args.every(a => Number.isFinite(Number(a))); }","tryCatchPattern":"try {\n  await dm.addAction({id: 'add_data_field', expression: expr});\n} catch (e) {\n  if (String(e).includes('random(min, max) requires two')) {\n    expr.args = [String(min), String(max)];\n    return retry();\n  }\n  throw e;\n}","preventionTips":["Always send both min and max as integers","Use form inputs that enforce two numeric fields for the random command","Validate arg counts per command before submitting the action"],"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"}