Home / Function/ from_components() — langchain Function Reference

from_components() — langchain Function Reference

Architecture documentation for the from_components() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a1a96dfd_ae4c_e804_cc3c_fa1f0626d568["from_components()"]
  6605de10_a777_2f31_c097_c8959e1f5cd1["StructuredQueryOutputParser"]
  a1a96dfd_ae4c_e804_cc3c_fa1f0626d568 -->|defined in| 6605de10_a777_2f31_c097_c8959e1f5cd1
  7c645a0f_77f7_93a6_94ee_217db357131a["load_query_constructor_chain()"]
  7c645a0f_77f7_93a6_94ee_217db357131a -->|calls| a1a96dfd_ae4c_e804_cc3c_fa1f0626d568
  8be56ad0_9949_1505_8cd9_95bdbee1ff5d["load_query_constructor_runnable()"]
  8be56ad0_9949_1505_8cd9_95bdbee1ff5d -->|calls| a1a96dfd_ae4c_e804_cc3c_fa1f0626d568
  8c121d4b_613e_c49b_ff2d_343e311f21b1["parse()"]
  a1a96dfd_ae4c_e804_cc3c_fa1f0626d568 -->|calls| 8c121d4b_613e_c49b_ff2d_343e311f21b1
  1dd3f637_7293_fa5f_5280_0c8be3cef4a9["fix_filter_directive()"]
  a1a96dfd_ae4c_e804_cc3c_fa1f0626d568 -->|calls| 1dd3f637_7293_fa5f_5280_0c8be3cef4a9
  style a1a96dfd_ae4c_e804_cc3c_fa1f0626d568 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/query_constructor/base.py lines 72–111

    def from_components(
        cls,
        allowed_comparators: Sequence[Comparator] | None = None,
        allowed_operators: Sequence[Operator] | None = None,
        allowed_attributes: Sequence[str] | None = None,
        fix_invalid: bool = False,  # noqa: FBT001,FBT002
    ) -> StructuredQueryOutputParser:
        """Create a structured query output parser from components.

        Args:
            allowed_comparators: allowed comparators
            allowed_operators: allowed operators
            allowed_attributes: allowed attributes
            fix_invalid: whether to fix invalid filter directives

        Returns:
            a structured query output parser
        """
        ast_parse: Callable
        if fix_invalid:

            def ast_parse(raw_filter: str) -> FilterDirective | None:
                filter_directive = cast(
                    "FilterDirective | None",
                    get_parser().parse(raw_filter),
                )
                return fix_filter_directive(
                    filter_directive,
                    allowed_comparators=allowed_comparators,
                    allowed_operators=allowed_operators,
                    allowed_attributes=allowed_attributes,
                )

        else:
            ast_parse = get_parser(
                allowed_comparators=allowed_comparators,
                allowed_operators=allowed_operators,
                allowed_attributes=allowed_attributes,
            ).parse
        return cls(ast_parse=ast_parse)

Subdomains

Frequently Asked Questions

What does from_components() do?
from_components() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/query_constructor/base.py.
Where is from_components() defined?
from_components() is defined in libs/langchain/langchain_classic/chains/query_constructor/base.py at line 72.
What does from_components() call?
from_components() calls 2 function(s): fix_filter_directive, parse.
What calls from_components()?
from_components() is called by 2 function(s): load_query_constructor_chain, load_query_constructor_runnable.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free