fix_filter_directive() — langchain Function Reference
Architecture documentation for the fix_filter_directive() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1dd3f637_7293_fa5f_5280_0c8be3cef4a9["fix_filter_directive()"] 7225abf9_cc63_55f0_0ae9_9fa5685b39ff["base.py"] 1dd3f637_7293_fa5f_5280_0c8be3cef4a9 -->|defined in| 7225abf9_cc63_55f0_0ae9_9fa5685b39ff a1a96dfd_ae4c_e804_cc3c_fa1f0626d568["from_components()"] a1a96dfd_ae4c_e804_cc3c_fa1f0626d568 -->|calls| 1dd3f637_7293_fa5f_5280_0c8be3cef4a9 style 1dd3f637_7293_fa5f_5280_0c8be3cef4a9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/query_constructor/base.py lines 114–167
def fix_filter_directive(
filter: FilterDirective | None, # noqa: A002
*,
allowed_comparators: Sequence[Comparator] | None = None,
allowed_operators: Sequence[Operator] | None = None,
allowed_attributes: Sequence[str] | None = None,
) -> FilterDirective | None:
"""Fix invalid filter directive.
Args:
filter: Filter directive to fix.
allowed_comparators: allowed comparators. Defaults to all comparators.
allowed_operators: allowed operators. Defaults to all operators.
allowed_attributes: allowed attributes. Defaults to all attributes.
Returns:
Fixed filter directive.
"""
if (
not (allowed_comparators or allowed_operators or allowed_attributes)
) or not filter:
return filter
if isinstance(filter, Comparison):
if allowed_comparators and filter.comparator not in allowed_comparators:
return None
if allowed_attributes and filter.attribute not in allowed_attributes:
return None
return filter
if isinstance(filter, Operation):
if allowed_operators and filter.operator not in allowed_operators:
return None
args = [
cast(
"FilterDirective",
fix_filter_directive(
arg,
allowed_comparators=allowed_comparators,
allowed_operators=allowed_operators,
allowed_attributes=allowed_attributes,
),
)
for arg in filter.arguments
if arg is not None
]
if not args:
return None
if len(args) == 1 and filter.operator in (Operator.AND, Operator.OR):
return args[0]
return Operation(
operator=filter.operator,
arguments=args,
)
return filter
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does fix_filter_directive() do?
fix_filter_directive() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/query_constructor/base.py.
Where is fix_filter_directive() defined?
fix_filter_directive() is defined in libs/langchain/langchain_classic/chains/query_constructor/base.py at line 114.
What calls fix_filter_directive()?
fix_filter_directive() is called by 1 function(s): from_components.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free