Home / Function/ _filter_injected_args() — langchain Function Reference

_filter_injected_args() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a["_filter_injected_args()"]
  5ebe56ae_0ac8_cb13_b5a9_ee567b924009["BaseTool"]
  fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a -->|defined in| 5ebe56ae_0ac8_cb13_b5a9_ee567b924009
  51b059af_20e0_9233_077d_cd590dd94dc8["run()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1["arun()"]
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1 -->|calls| fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a
  967c88a4_f24b_828c_a121_3b72c0a58b0b["get_all_basemodel_annotations()"]
  fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a -->|calls| 967c88a4_f24b_828c_a121_3b72c0a58b0b
  5c55c769_8605_2bfb_879c_38c645ebb4f8["_is_injected_arg_type()"]
  fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a -->|calls| 5c55c769_8605_2bfb_879c_38c645ebb4f8
  style fa82d3e5_c342_0a6d_3c6f_5aa889ad3f2a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tools/base.py lines 803–836

    def _filter_injected_args(self, tool_input: dict) -> dict:
        """Filter out injected tool arguments from the input dictionary.

        Injected arguments are those annotated with `InjectedToolArg` or its
        subclasses, or arguments in `FILTERED_ARGS` like `run_manager` and callbacks.

        Args:
            tool_input: The tool input dictionary to filter.

        Returns:
            A filtered dictionary with injected arguments removed.
        """
        # Start with filtered args from the constant
        filtered_keys = set[str](FILTERED_ARGS)

        # Add injected args from function signature (e.g., ToolRuntime parameters)
        filtered_keys.update(self._injected_args_keys)

        # If we have an args_schema, use it to identify injected args
        if self.args_schema is not None:
            try:
                annotations = get_all_basemodel_annotations(self.args_schema)
                for field_name, field_type in annotations.items():
                    if _is_injected_arg_type(field_type):
                        filtered_keys.add(field_name)
            except Exception:
                # If we can't get annotations, just use FILTERED_ARGS
                _logger.debug(
                    "Failed to get args_schema annotations for filtering.",
                    exc_info=True,
                )

        # Filter out the injected keys from tool_input
        return {k: v for k, v in tool_input.items() if k not in filtered_keys}

Subdomains

Called By

Frequently Asked Questions

What does _filter_injected_args() do?
_filter_injected_args() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is _filter_injected_args() defined?
_filter_injected_args() is defined in libs/core/langchain_core/tools/base.py at line 803.
What does _filter_injected_args() call?
_filter_injected_args() calls 2 function(s): _is_injected_arg_type, get_all_basemodel_annotations.
What calls _filter_injected_args()?
_filter_injected_args() is called by 2 function(s): arun, run.

Analyze Your Own Codebase

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

Try Supermodel Free