{"record":{"id":"374f98059cd9203f","repo":"HumanSignal/label-studio","slug":"choices-values-list-weights-list-requires-one-or","errorCode":null,"errorMessage":"choices(values:list, weights:list) requires one or two arguments.","messagePattern":"choices\\(values:list, weights:list\\) requires one or two arguments\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":304,"sourceCode":"\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)\n    for task_batch in batched_iterator(task_iterator, settings.UPDATE_COLUMN_BATCH_SIZE):\n        if command == 'range':\n            for index, task in enumerate(task_batch):\n                task.data[value_name] = start + offset + index\n        elif command == 'sample':","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L286-L322","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{\"command\": \"choices\", \"args\": [\"[\\\"a\\\",\\\"b\\\"]\", \"[0.5,0.5]\", \"42\"]}\n// after\n{\"command\": \"choices\", \"args\": [\"[\\\"a\\\",\\\"b\\\"]\", \"[0.5,0.5]\"]}","handlingStrategy":"validation","validationCode":"if (expr.command === 'choices') {\n  const n = (expr.args || []).length;\n  if (n !== 1 && n !== 2) throw new Error('choices requires [values] or [values, weights]');\n}","typeGuard":"function isValidChoices(e) { const n = (e.args || []).length; return e.command === 'choices' && (n === 1 || n === 2); }","tryCatchPattern":"try {\n  await dm.addAction({id: 'add_data_field', expression: expr});\n} catch (e) {\n  if (String(e).includes('choices(values:list, weights:list)')) normalizeChoicesArgs(expr);\n  else throw e;\n}","preventionTips":["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"],"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"}