HumanSignal/label-studio · error · ValidationError
choices(values:list, weights:list) requires one or two argum
Error message
choices(values:list, weights:list) requires one or two arguments.
What it means
The DataManager 'choices' expression picks values (optionally weighted) for a column. add_expression requires one argument (values list) or two (values list + weights list); zero or three-or-more arguments raise this ValidationError.
Source
Thrown at label_studio/data_manager/actions/data_columns.py:304
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)
for task_batch in batched_iterator(task_iterator, settings.UPDATE_COLUMN_BATCH_SIZE):
if command == 'range':
for index, task in enumerate(task_batch):
task.data[value_name] = start + offset + index
elif command == 'sample':View on GitHub (pinned to 0b49e9b539)
Solutions
- Pass exactly one JSON-encoded values list: {"args": ["[\"a\",\"b\"]"]}
- For weighted choices pass exactly two args: values then weights, e.g. {"args": ["[\"a\",\"b\"]", "[0.7,0.3]"]}
- Ensure args elements are JSON strings (json.loads is applied to each), not nested objects
Example fix
// before
{"command": "choices", "args": ["[\"a\",\"b\"]", "[0.5,0.5]", "42"]}
// after
{"command": "choices", "args": ["[\"a\",\"b\"]", "[0.5,0.5]"]} Defensive patterns
Strategy: validation
Validate before calling
if (expr.command === 'choices') {
const n = (expr.args || []).length;
if (n !== 1 && n !== 2) throw new Error('choices requires [values] or [values, weights]');
} Type guard
function isValidChoices(e) { const n = (e.args || []).length; return e.command === 'choices' && (n === 1 || n === 2); } Try / catch
try {
await dm.addAction({id: 'add_data_field', expression: expr});
} catch (e) {
if (String(e).includes('choices(values:list, weights:list)')) normalizeChoicesArgs(expr);
else throw e;
} Prevention
- JSON-encode each arg element as a string (json.loads is applied per element)
- Pass weights only together with values, never alone
- Keep the weights length aligned with the values length
When it happens
Trigger: Calling the add-data-field action with {"command": "choices", "args": []} or with three+ args; passing weights without values or extra trailing arguments via _stage_column_mutation / _apply_column_mutation.
Common situations: Omitting the values array entirely; passing values, weights, and a third seed/count argument; sending already-parsed JSON lists instead of JSON strings as args elements.
Related errors
- sample() does not accept arguments.
- random(min, max) requires two arguments.
- 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/374f98059cd9203f.
Report an issue: GitHub.