def METHOD_NAME(text: str, max_length: int = 50) -> str:
    text = _slugify.sub("", text.lower()).strip()
    parts = re.split(r"\s+", text)
    result = parts[0]
    for p in parts[1:]:
        new = result + "_" + p
        if len(new) > max_length:
            break
        result = new
    return result[:max_length]