mem0ai/mem0 · error · ValueError
Filter value for {key!r} contains prohibited characters (dou
Error message
Filter value for {key!r} contains prohibited characters (double quote or backslash): {value!r} What it means
Raised by `_validate_filter` when a string filter value contains a double quote or a backslash. The Upstash filter is built by string interpolation, so these characters could terminate or alter the quoted literal — rejecting them is the injection defense. Values are otherwise passed through verbatim, so escaping is deliberately not attempted.
Source
Thrown at mem0/vector_stores/upstash_vector.py:29
except ImportError:
raise ImportError("The 'upstash_vector' library is required. Please install it using 'pip install upstash_vector'.")
logger = logging.getLogger(__name__)
_SAFE_FILTER_KEY = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*\Z")
def _validate_filter(key: str, value: Any) -> None:
if not isinstance(key, str) or not _SAFE_FILTER_KEY.fullmatch(key):
raise ValueError(f"Invalid filter key: {key!r}")
if not isinstance(value, (str, int, float, bool)):
raise ValueError(
f"Filter value for {key!r} must be str, int, float, or bool, "
f"got {type(value).__name__}"
)
if isinstance(value, str) and ('"' in value or "\\" in value):
raise ValueError(
f"Filter value for {key!r} contains prohibited characters "
f"(double quote or backslash): {value!r}"
)
class OutputData(BaseModel):
id: Optional[str] # memory id
score: Optional[float] # is None for `get` method
payload: Optional[Dict] # metadata
class UpstashVector(VectorStoreBase):
def __init__(
self,
collection_name: str,
url: Optional[str] = None,
token: Optional[str] = None,
client: Optional[Index] = None,View on GitHub (pinned to 001c235229)
Solutions
- Sanitize at the boundary: strip or reject `"` and `\\` in any value destined for an Upstash filter.
- Better, filter on stable identifiers (IDs, slugs, hashes) instead of free-form text — store the text in the payload, match on the identifier.
- If the character matters, encode it (e.g. percent-encoding or a hash of the value) consistently at write and read time.
Example fix
# before
name = 'assistant "pro"'
memory.search("q", filters={"agent_name": name}) # ValueError
# after
import hashlib
slug = "assistant-pro" # or hashlib.sha256(name.encode()).hexdigest()
memory.add("...", metadata={"agent_name": name, "agent_slug": slug})
memory.search("q", filters={"agent_slug": slug}) Defensive patterns
Strategy: validation
Validate before calling
def safe_filter_value(value: str) -> str:
if '\"' in value or "\\" in value:
raise ValueError("Filter value contains double quote or backslash; filter on an identifier instead")
return value Type guard
def is_safe_filter_string(v) -> bool:
return isinstance(v, str) and '\"' not in v and "\\" not in v Try / catch
try:
results = memory.search("q", filters=filters)
except ValueError as e:
if "prohibited characters" in str(e):
raise BadRequest("Filter values must not contain quotes or backslashes") from e
raise Prevention
- Filter on stable identifiers (IDs, slugs, hashes), never free-form user text.
- Reject quote/backslash characters at the API boundary — the library intentionally does not escape them.
- When text matching is needed, move the check client-side over returned payloads.
When it happens
Trigger: Filtering on values containing `"` (e.g. agent names like `assistant "pro"`), Windows-style paths with backslashes (`C:\Users\...`), or crafted input such as `u1" OR 1=1 --` attempting filter injection.
Common situations: User-supplied free text (chat titles, agent names, tags) used directly as an equality filter value; LLM-generated filter values quoting terms; passing regexes or file paths as metadata filters.
Related errors
- Invalid filter key: {key!r}
- Filter value for {key!r} must be str, int, float, or bool, g
- AND filter value must be a list of filter dicts, got ${typeo
- OR filter value must be a list of filter dicts, got ${typeof
- NOT filter value must be a list of filter dicts, got ${typeo
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/dc0b7c87732de0d8.
Report an issue: GitHub.