{"record":{"id":"983add7948d40074","repo":"HumanSignal/label-studio","slug":"validation-failed-on","errorCode":null,"errorMessage":"Validation failed on {}: {}","messagePattern":"Validation failed on (.+?): (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"label_studio/core/label_config.py","lineNumber":122,"sourceCode":"    return config, etree.tostring(xml, encoding='unicode')\n\n\ndef validate_label_config(config_string: Union[str, None]) -> None:\n    # xml and schema\n    try:\n        config, cleaned_config_string = parse_config_to_json(config_string)\n        jsonschema.validate(config, _LABEL_CONFIG_SCHEMA_DATA)\n    except (etree.ParseError, ValueError) as exc:\n        raise ValidationError(str(exc))\n    except jsonschema.exceptions.ValidationError as exc:\n        # jsonschema4 validation error now includes all errors from \"anyOf\" subschemas\n        # check https://python-jsonschema.readthedocs.io/en/latest/errors/#jsonschema.exceptions.ValidationError.context\n        # we pick the first failed schema and show only its error message\n        error_message = exc.context[0].message if len(exc.context) else exc.message\n        error_message = 'Validation failed on {}: {}'.format(\n            '/'.join(map(str, exc.path)), error_message.replace('@', '')\n        )\n        raise ValidationError(error_message)\n\n    # unique names in config # FIXME: 'name =' (with spaces) won't work\n    all_names = re.findall(r'(?:^|[^\\w])name=\"([^\"]*)\"', cleaned_config_string)\n    if len(set(all_names)) != len(all_names):\n        raise ValidationError('Label config contains non-unique names: ' + ', '.join(all_names))\n\n    # toName points to existent name\n    names = set(all_names)\n    toNames = re.findall(r'toName=\"([^\"]*)\"', cleaned_config_string)\n    for toName_ in toNames:\n        for toName in toName_.split(','):\n            if toName not in names:\n                raise ValidationError(f'toName=\"{toName}\" not found in names: {sorted(names)}')\n\n    # Tag attribute validation (e.g. Video playback speed) via SDK\n    try:\n        li = LabelInterface(config_string)\n        if hasattr(li, '_tag_attribute_validation'):","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/core/label_config.py#L104-L140","documentation":"validate_label_config wraps jsonschema ValidationError into a Django/DRF ValidationError with a friendlier message: 'Validation failed on <json path>: <detail>'. The label config XML string must conform to Label Studio's JSON schema; any schema violation surfaces here, with the failing JSON path and the first sub-error's message.","triggerScenarios":"Calling validate_label_config (directly or via project config save/import APIs) with a label config string that fails jsonschema validation — e.g. unknown tags, missing required attributes, wrong value types. Raised when exc.context exists (first context message used) or falls back to exc.message.","commonSituations":"Copy-pasting configs from other tools; hand-written XML with typos in tag or attribute names; using tags unsupported by the installed Label Studio version; missing required attributes like name/toName/value.","solutions":["Read the JSON path in the message — it pinpoints the failing element/attribute; fix that tag or attribute.","Validate the config against Label Studio's documented tag reference for your version (unsupported tags fail schema).","Check for required attributes (name, toName, value) on each tag.","Test the config in the Label Studio UI's labeling config editor, which reports schema errors interactively."],"exampleFix":"<!-- before -->\n<Text name=\"text\" value=\"$text\"/>\n<!-- after: name, toName and a valid choice tag pairing -->\n<Text name=\"text\" value=\"$text\"/>\n<Choices name=\"sentiment\" toName=\"text\">\n  <Choice value=\"positive\"/>\n</Choices>","handlingStrategy":"try-catch","validationCode":"import jsonschema\nschema = get_label_config_schema()  # from your Label Studio install\njsonschema.validate(cleaned_config_string_or_parsed, schema)","typeGuard":"def is_valid_label_config(config: str) -> bool:\n    from core.label_config import validate_label_config\n    try:\n        validate_label_config(config)\n        return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    validate_label_config(config)\nexcept ValidationError as e:\n    logger.warning('Invalid label config: %s', e.detail if hasattr(e, 'detail') else e)\n    return Response({'error': str(e)}, status=400)","preventionTips":["Compose configs from Label Studio templates instead of hand-writing XML.","Validate in the UI config editor before saving via API.","Pin and consult the tag reference for your Label Studio version.","Add a pre-save schema validation step in CI for config files."],"tags":["validation","label-config","jsonschema"],"backgroundTag":"schema-validation-failed","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}