from typing import Union


def _sanitize_value(value: str) -> Union[int, str, None]:
    """
    Sanitize a value read from a CSV file as following:
     * if its equal to 'null' -> None
     * if starts with quote -> str
     * otherwise -> int - if casting fails, a ValueError is raised

    :param value: the value to sanitize
    :return: sanitized value
    """
    value = value.strip(' ')
    if value.startswith('"'):
        # it's a string
        return value.strip('"')

    if value.lower() == 'null':
        return None

    return int(value)