redis/redis-py · error · ValueError

At least one tag must be specified

Error message

At least one tag must be specified

What it means

Raised by redis.commands.search.querystring.tags() when called with no tag arguments. The function builds a tag-value expression {@field:{tag1|tag2}} and requires at least one tag to be meaningful. Passing zero tags is treated as a caller bug.

Source

Thrown at redis/commands/search/querystring.py:10

def tags(*t):
    """
    Indicate that the values should be matched to a tag field

    ### Parameters

    - **t**: Tags to search for
    """
    if not t:
        raise ValueError("At least one tag must be specified")
    return TagValue(*t)


def between(a, b, inclusive_min=True, inclusive_max=True):
    """
    Indicate that value is a numeric range
    """
    return RangeValue(a, b, inclusive_min=inclusive_min, inclusive_max=inclusive_max)


def equal(n):
    """
    Match a numeric value
    """
    return between(n, n)


def lt(n):

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Ensure at least one tag is passed: tags('red', 'blue').
  2. Guard dynamic inputs: only call tags(*selected) when selected is non-empty, otherwise omit the tag clause.
  3. Default to a sentinel/wildcard if an empty selection should match all.

Example fix

// before
expr = tags(*selected_tags)  # fails when empty
// after
expr = tags(*selected_tags) if selected_tags else None
Defensive patterns

Strategy: validation

Validate before calling

from redis.commands.search import querystring

def safe_tags(*t):
    if not t:
        return None  # caller omits the clause
    return querystring.tags(*t)

Type guard

def has_tags(t) -> bool:
    return bool(t)

Try / catch

try:
    node = querystring.tags(*selected)
except ValueError:
    node = None  # no tag clause

Prevention

When it happens

Trigger: Calling tags() with no positional args, or tags(*[]) / tags(*empty_list) where the list unpacks to nothing, typically inside a dynamic query builder.

Common situations: Building a tag filter from user input where the user selected no tags; iterating over an empty collection and forwarding it to tags(); conditional tag logic that forgets the empty case.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/d0a0ad331642c8e9.json. Report an issue: GitHub.