HumanSignal/label-studio · error · ValidationError

Incorrect value in key "{key}" = "{value}". It should be dig

Error message

Incorrect value in key "{key}" = "{value}". It should be digit string.

What it means

int_from_request coerces the value of a request parameter keyed by `key` to int. If the value is a string that int() cannot parse (ValueError), it raises DRF ValidationError mapping the key to 'Incorrect value in key ... It should be digit string.' Other unexpected exceptions are also wrapped as ValidationError with the exception text.

Source

Thrown at label_studio/core/utils/params.py:51

        raise ValidationError({key: str(e)})


def int_from_request(params, key, default):
    """Get integer from request GET, POST, etc

    :param params: dict POST, GET, etc
    :param key: key to find
    :param default: default value
    :return: int
    """
    value = params.get(key, default)

    # str
    if isinstance(value, str):
        try:
            return int(value)
        except ValueError:
            raise ValidationError({key: f'Incorrect value in key "{key}" = "{value}". It should be digit string.'})
        except Exception as e:
            raise ValidationError({key: str(e)})
    # int
    elif isinstance(value, int):
        return value
    # other
    else:
        raise ValidationError(
            {key: f'Incorrect value type in key "{key}" = "{value}". It should be digit string or integer.'}
        )


def float_from_request(params, key, default):
    """Get float from request GET, POST, etc

    :param params: dict POST, GET, etc
    :param key: key to find
    :param default: default value

View on GitHub (pinned to 0b49e9b539)

Solutions

  1. Send a valid base-10 digit string (e.g. page=2, id=42); the message points at the offending key and value.
  2. On the client, coerce/validate numeric inputs before building the request.
  3. Handle DRF ValidationError (HTTP 400) gracefully and show a friendly message; retry with a corrected value.
  4. Check for empty strings — an empty value also fails int() parsing.

Example fix

// before
GET /api/tasks/?page=two
// after
GET /api/tasks/?page=2
Defensive patterns

Strategy: try-catch

Validate before calling

def is_digit_string(v) -> bool:
    return isinstance(v, int) or (isinstance(v, str) and v.isdigit())

Try / catch

try:
    page = int_from_request(request.query_params, 'page', 1)
except ValidationError as e:
    return Response({'error': e.detail, 'hint': 'page must be a digit string'}, status=400)

Prevention

When it happens

Trigger: Calling int_from_request (directly or via paginator/get/post/get_prepare_params) with a non-numeric string for an integer parameter — e.g. ?page=abc, ?id=1.5, ?project=first, or empty string.

Common situations: Users hand-editing paginated API URLs; frontends sending placeholder or NaN-ish values; IDs pasted with extra characters; empty query params (?page=).

Related errors


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