def valid_sort(sort, allow_empty=False):
    """Returns validated sort name or throws Assert."""
    assert isinstance(sort, str), 'sort must be a string'
    if not (allow_empty and sort == ''):
        valid_sorts = ['trending', 'promoted', 'hot', 'created']
        assert sort in valid_sorts, 'invalid sort'
    return sort