def to_bool(val):
    """Convert a value to a bool."""
    if isinstance(val, bool):
        return val
    if isinstance(val, str):
        return val.lower() not in ("", "0", "false")
    return bool(val)