{"record":{"id":"be20c4a77b72c11b","repo":"HumanSignal/label-studio","slug":"all-items-in-the-list-must-be-strings","errorCode":null,"errorMessage":"All items in the list must be strings","messagePattern":"All items in the list must be strings","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"label_studio/ml_models/models.py","lineNumber":29,"sourceCode":"from rest_framework.exceptions import ValidationError\nfrom tasks.models import Annotation, FailedPrediction, Prediction, PredictionMeta\n\nlogger = logging.getLogger(__name__)\n\n\n# skills are partitions of projects (label config + input columns + output columns) into categories of labeling tasks\nclass SkillNames(models.TextChoices):\n    TEXT_CLASSIFICATION = 'TextClassification', _('TextClassification')\n    NAMED_ENTITY_RECOGNITION = 'NamedEntityRecognition', _('NamedEntityRecognition')\n\n\ndef validate_string_list(value):\n    if not value:\n        raise ValidationError('list should not be empty')\n    if not isinstance(value, list):\n        raise ValidationError('Value must be a list')\n    if not all(isinstance(item, str) for item in value):\n        raise ValidationError('All items in the list must be strings')\n\n\nclass ModelInterface(models.Model):\n    title = models.CharField(_('title'), max_length=500, null=False, blank=False, help_text='Model name')\n\n    description = models.TextField(_('description'), null=True, blank=True, help_text='Model description')\n\n    created_by = models.ForeignKey(\n        settings.AUTH_USER_MODEL, related_name='created_models', on_delete=models.SET_NULL, null=True\n    )\n\n    created_at = models.DateTimeField(_('created at'), auto_now_add=True)\n\n    updated_at = models.DateTimeField(_('updated at'), auto_now=True)\n\n    organization = models.ForeignKey(\n        'organizations.Organization', on_delete=models.CASCADE, related_name='model_interfaces', null=True\n    )","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/ml_models/models.py#L11-L47","documentation":"DRF ValidationError from validate_string_list raised when every element check fails: the list contains non-string items (ints, dicts, nulls, etc.).","triggerScenarios":"Submitting a list like [1,2,3] or [{...}] for a ModelInterface list field that must contain only strings.","commonSituations":"ML backend returning enum codes/ints instead of string names; clients sending numeric ids for labels or controls; JSON payloads with mixed types.","solutions":["Convert items to strings before submission (map str(item))","Fix the ML backend to return string values for the interface lists","Coerce in the serializer/model if numeric ids should be accepted"],"exampleFix":"// before\n{\"labels\": [1, 2, 3]}\n// after\n{\"labels\": [\"1\", \"2\", \"3\"]}","handlingStrategy":"type-guard","validationCode":"if not all(isinstance(i, str) for i in value):\n    value = [str(i) for i in value]","typeGuard":"def all_strings(v: list) -> bool:\n    return isinstance(v, list) and all(isinstance(i, str) for i in v)","tryCatchPattern":"try:\n    interface.full_clean()\nexcept ValidationError as e:\n    if 'must be strings' in str(e):\n        interface.labels = [str(x) for x in interface.labels]\n        interface.full_clean()","preventionTips":["Normalize ML backend output to string names, not numeric codes","Coerce items with str() before submitting","Add schema validation requiring string items in lists"],"tags":["validation","ml","type-error","drf"],"backgroundTag":"type-validation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}