HumanSignal/label-studio · error · ValidationError
random(min, max) requires two arguments.
Error message
random(min, max) requires two arguments.
What it means
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).
Source
Thrown at label_studio/data_manager/actions/data_columns.py:299
args = [] if len(args) == 1 and args[0] == '' else args
for i, arg in enumerate(args):
args[i] = arg.replace(';', ',').replace("'", '"')
sample_values = None
if command == 'range':
if len(args) != 1:
raise ValidationError({'value': 'range(start:int) requires one start argument.'})
start = int(args[0])
elif command == 'sample':
if args:
raise ValidationError({'value': 'sample() does not accept arguments.'})
sample_values = iter(random.sample(range(0, size), size))
elif command == 'random':
if len(args) != 2:
raise ValidationError({'value': 'random(min, max) requires two arguments.'})
minimum, maximum = int(args[0]), int(args[1])
elif command == 'choices':
if not 0 < len(args) < 3:
raise ValidationError({'value': 'choices(values:list, weights:list) requires one or two arguments.'})
weights = json.loads(args[1]) if len(args) == 2 else None
choices = json.loads(args[0])
elif command == 'replace':
if len(args) != 2:
raise ValidationError({'value': 'replace(old_value, new_value) requires two arguments.'})
old_value, new_value = json.loads(args[0]), json.loads(args[1])
else:
raise ValidationError('Undefined expression, you can use: ' + add_data_field_examples)
offset = 0
task_iterator = iterate_queryset(queryset.only('id', 'data'), chunk_size=settings.UPDATE_COLUMN_BATCH_SIZE)View on GitHub (pinned to 0b49e9b539)
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
Example fix
// before
{"command": "random", "args": ["10"]}
// after
{"command": "random", "args": ["0", "10"]} Defensive patterns
Strategy: validation
Validate before calling
if (expr.command === 'random' && (!Array.isArray(expr.args) || expr.args.length !== 2)) {
throw new Error('random requires exactly [min, max]');
} Type guard
function isValidRandom(e) { return e.command === 'random' && Array.isArray(e.args) && e.args.length === 2 && e.args.every(a => Number.isFinite(Number(a))); } Try / catch
try {
await dm.addAction({id: 'add_data_field', expression: expr});
} catch (e) {
if (String(e).includes('random(min, max) requires two')) {
expr.args = [String(min), String(max)];
return retry();
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- sample() does not accept arguments.
- choices(values:list, weights:list) requires one or two argum
- replace(old_value, new_value) requires two arguments.
- Undefined expression, you can use: {add_data_field_examples}
- Can't find '{action_id}' in registered actions
AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29).
Data as JSON: /api/errors/c6342ae754edeb96.
Report an issue: GitHub.