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
- Ensure at least one tag is passed: tags('red', 'blue').
- Guard dynamic inputs: only call tags(*selected) when selected is non-empty, otherwise omit the tag clause.
- 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
- Check the tag list is non-empty before calling tags().
- Treat an empty tag selection as 'omit the clause', not as an error to surface.
- Unit-test dynamic query builders with empty inputs.
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
- index_type must be one of {list(IndexType)}
- prefix must be provided
- Did not receive a Filter object.
- Did not receive a SortByField.
- collect fields must be '*' or a non-empty list of names
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/d0a0ad331642c8e9.json.
Report an issue: GitHub.