langchain-ai/langchain · error · ValueError
Received disallowed operator {func}. Allowed comparators are
Error message
Received disallowed operator {func}. Allowed comparators are {self.allowed_operators} What it means
Translator base class for structured-query translation (`langchain_core.structured_query.BaseTranslator`) validates that every `Operator` it is asked to visit is in the translator's `allowed_operators` set. Raised when a Visitor/translator receives a logical operator the target backend does not support — typically inside `visit_operation` during filter translation for a vector store.
Source
Thrown at libs/core/langchain_core/structured_query.py:34
"""Defines interface for IR translation using a visitor pattern."""
allowed_comparators: Sequence[Comparator] | None = None
"""Allowed comparators for the visitor."""
allowed_operators: Sequence[Operator] | None = None
"""Allowed operators for the visitor."""
def _validate_func(self, func: Operator | Comparator) -> None:
if (
isinstance(func, Operator)
and self.allowed_operators is not None
and func not in self.allowed_operators
):
msg = (
f"Received disallowed operator {func}. Allowed "
f"comparators are {self.allowed_operators}"
)
raise ValueError(msg)
if (
isinstance(func, Comparator)
and self.allowed_comparators is not None
and func not in self.allowed_comparators
):
msg = (
f"Received disallowed comparator {func}. Allowed "
f"comparators are {self.allowed_comparators}"
)
raise ValueError(msg)
@abstractmethod
def visit_operation(self, operation: Operation) -> Any:
"""Translate an Operation.
Args:
operation: Operation to translate.
"""View on GitHub (pinned to e32fa9a52e)
Solutions
- Check `<translator>.allowed_operators` for your store and constrain the LLM's filter generation (adjust the self-query prompt/metadata schema) to only those operators.
- Restructure the query so unsupported operators are not needed (e.g. expand `in` into an `or` chain if `or` is allowed).
- If you own the translator subclass, extend `allowed_operators` and implement the corresponding `visit_operation` branches.
Example fix
# before
filt = Operator.IN(...) # sent to translator with allowed_operators=[AND, OR]
translator.visit_operation(filt.astree)
# after
filt = or_(Comparison('eq', 'tag', 'a'), Comparison('eq', 'tag', 'b'))
translator.visit_operation(filt.astree) Defensive patterns
Strategy: validation
Validate before calling
allowed = set(translator.allowed_operators or [])
ops_in_filter = collect_operators(filter_expr) # walk expr, gather Operator nodes
unsupported = ops_in_filter - allowed
if unsupported:
filter_expr = rewrite_to_supported(filter_expr, allowed) # e.g. expand IN into OR Type guard
def operator_allowed(translator, op) -> bool:
return translator.allowed_operators is None or op in translator.allowed_operators Try / catch
try:
translated = translator.visit_operation(expr)
except ValueError as e:
if 'disallowed operator' in str(e):
expr = simplify_filter(expr, allowed=set(translator.allowed_operators))
translated = translator.visit_operation(expr)
else:
raise Prevention
- Read the store translator's allowed_operators before generating filters.
- Constrain self-query prompts to the supported operator set.
- Prefer post-filtering in Python for exotic operators.
When it happens
Trigger: Translating a `FilterExpression` containing `and`/`or`/`not`/`in` operators to a vector store whose translator only allows a subset, e.g. sending an `in` operator to a store whose `allowed_operators = [Operator.AND, Operator.OR]`; self-querying retrievers built on stores with restricted operator support.
Common situations: Using `SelfQueryRetriever` with a vectorstore that does not support `in`/`not` and the LLM emits such a filter; switching a working self-query pipeline to a different backend (e.g. Pinecone → Chroma) with narrower operator support; custom translators forgetting to widen `allowed_operators`.
Related errors
- Received disallowed comparator {func}. Allowed comparators a
- The delete operation to VectorStore failed.
- Vectorstore should be either a VectorStore or a DocumentInde
- Vectorstore {destination} does not have required method {met
- Vectorstore has not implemented the delete method
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/a1ebf6e0e568520e.
Report an issue: GitHub.