HumanSignal/label-studio · error · ValidationError

Validation failed on {}: {}

Error message

Validation failed on {}: {}

What it means

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.

Source

Thrown at label_studio/core/label_config.py:122

    return config, etree.tostring(xml, encoding='unicode')


def validate_label_config(config_string: Union[str, None]) -> None:
    # xml and schema
    try:
        config, cleaned_config_string = parse_config_to_json(config_string)
        jsonschema.validate(config, _LABEL_CONFIG_SCHEMA_DATA)
    except (etree.ParseError, ValueError) as exc:
        raise ValidationError(str(exc))
    except jsonschema.exceptions.ValidationError as exc:
        # jsonschema4 validation error now includes all errors from "anyOf" subschemas
        # check https://python-jsonschema.readthedocs.io/en/latest/errors/#jsonschema.exceptions.ValidationError.context
        # we pick the first failed schema and show only its error message
        error_message = exc.context[0].message if len(exc.context) else exc.message
        error_message = 'Validation failed on {}: {}'.format(
            '/'.join(map(str, exc.path)), error_message.replace('@', '')
        )
        raise ValidationError(error_message)

    # unique names in config # FIXME: 'name =' (with spaces) won't work
    all_names = re.findall(r'(?:^|[^\w])name="([^"]*)"', cleaned_config_string)
    if len(set(all_names)) != len(all_names):
        raise ValidationError('Label config contains non-unique names: ' + ', '.join(all_names))

    # toName points to existent name
    names = set(all_names)
    toNames = re.findall(r'toName="([^"]*)"', cleaned_config_string)
    for toName_ in toNames:
        for toName in toName_.split(','):
            if toName not in names:
                raise ValidationError(f'toName="{toName}" not found in names: {sorted(names)}')

    # Tag attribute validation (e.g. Video playback speed) via SDK
    try:
        li = LabelInterface(config_string)
        if hasattr(li, '_tag_attribute_validation'):

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Read the JSON path in the message — it pinpoints the failing element/attribute; fix that tag or attribute.
  2. Validate the config against Label Studio's documented tag reference for your version (unsupported tags fail schema).
  3. Check for required attributes (name, toName, value) on each tag.
  4. Test the config in the Label Studio UI's labeling config editor, which reports schema errors interactively.

Example fix

<!-- before -->
<Text name="text" value="$text"/>
<!-- after: name, toName and a valid choice tag pairing -->
<Text name="text" value="$text"/>
<Choices name="sentiment" toName="text">
  <Choice value="positive"/>
</Choices>
Defensive patterns

Strategy: try-catch

Validate before calling

import jsonschema
schema = get_label_config_schema()  # from your Label Studio install
jsonschema.validate(cleaned_config_string_or_parsed, schema)

Type guard

def is_valid_label_config(config: str) -> bool:
    from core.label_config import validate_label_config
    try:
        validate_label_config(config)
        return True
    except Exception:
        return False

Try / catch

try:
    validate_label_config(config)
except ValidationError as e:
    logger.warning('Invalid label config: %s', e.detail if hasattr(e, 'detail') else e)
    return Response({'error': str(e)}, status=400)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of HumanSignal/label-studio@0b49e9b539 (2026-08-29). Data as JSON: /api/errors/983add7948d40074. Report an issue: GitHub.