HumanSignal/label-studio · error · ValidationError
sample() does not accept arguments.
Error message
sample() does not accept arguments.
What it means
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.
Source
Thrown at label_studio/data_manager/actions/data_columns.py:294
command, args = value.split('(', 1)
if not command:
raise ValidationError({'value': 'Expression command is required.'})
args = process_arrays(args)
args = args.replace(')', '').split(',')
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])
View on GitHub (pinned to 0b49e9b539)
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
Example fix
// before
{"command": "sample", "args": ["100"]}
// after
{"command": "sample", "args": []} Defensive patterns
Strategy: validation
Validate before calling
if (expr.command === 'sample' && Array.isArray(expr.args) && expr.args.length > 0) {
throw new Error('sample() takes no arguments');
} Type guard
function isValidSample(e) { return e.command === 'sample' && (!e.args || e.args.length === 0); } Try / catch
try {
await dm.addAction({id: 'add_data_field', expression: expr});
} catch (e) {
if (String(e).includes('sample() does not accept arguments')) fixArgs(expr);
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- random(min, max) requires two 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/2d79511af5d0e46f.
Report an issue: GitHub.