{"record":{"id":"26586a4b9078494e","repo":"HumanSignal/label-studio","slug":"expression-must-use-the-form-command-arguments","errorCode":null,"errorMessage":"Expression must use the form command(arguments).","messagePattern":"Expression must use the form command\\(arguments\\)\\.","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/data_manager/actions/data_columns.py","lineNumber":275,"sourceCode":"    while start != end:\n        end = start + params[start:].find(']') + 1\n        params = params[0:start] + params[start:end].replace(',', ';') + params[end:]\n        start = end + params[end:].find('[') + 1\n    return params\n\n\nadd_data_field_examples = (\n    'range(2) or '\n    'sample() or '\n    'random(<min_int>, <max_int>) or '\n    'choices([\"<value1>\", \"<value2>\", ...], [<weight1>, <weight2>, ...]) or '\n    'replace(\"old-string\", \"new-string\")'\n)\n\n\ndef add_expression(queryset, size, value, value_name):\n    if '(' not in value or not value.endswith(')'):\n        raise ValidationError({'value': 'Expression must use the form command(arguments).'})\n    command, args = value.split('(', 1)\n    if not command:\n        raise ValidationError({'value': 'Expression command is required.'})\n    args = process_arrays(args)\n    args = args.replace(')', '').split(',')\n    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:","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/data_manager/actions/data_columns.py#L257-L293","documentation":"add_expression validates that an Expression column value has the shape command(arguments): it must contain '(' and end with ')'. Otherwise ValidationError {'value': 'Expression must use the form command(arguments).'} is raised. Expressions like 'range' or 'sample' without parentheses are invalid.","triggerScenarios":"Submitting value_type 'Expression' with value like 'range' (no parentheses), 'range(5' (missing closing paren), or 'x(' with nothing after.","commonSituations":"User typing just the command name in the dialog form; copy-paste losing the trailing ')'; templates showing range(start:int) copied verbatim.","solutions":["Wrap the expression in command(args) form, e.g. 'range(10)' or 'sample()'.","Ensure the value ends with ')' and contains at least one '('.","Fix the client to append parentheses when only a command name is given."],"exampleFix":"// before\nvalue = 'range'\n// after\nvalue = 'range(10)'","handlingStrategy":"validation","validationCode":"import re\nexpr = request_data.get('value', '')\nif request_data.get('value_type') == 'Expression':\n    assert '(' in expr and expr.endswith(')'), 'expression must be command(arguments)'","typeGuard":"def is_well_formed_expression(value):\n    return isinstance(value, str) and '(' in value and value.endswith(')')","tryCatchPattern":"from rest_framework.exceptions import ValidationError\ntry:\n    add_data_field(project, qs, request=request)\nexcept ValidationError as e:\n    if 'Expression must use the form' in str(e):\n        suggest_command_template()","preventionTips":["Use the dialog's command templates instead of typing raw expressions.","Validate expression shape client-side before submission.","Never copy placeholder text like 'range(start:int)' literally."],"tags":["django","validation","data-manager","expression"],"backgroundTag":"expression-syntax-error","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}