Home / Function/ _validate_and_resolve_path() — langchain Function Reference

_validate_and_resolve_path() — langchain Function Reference

Architecture documentation for the _validate_and_resolve_path() function in file_search.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b4e992f2_93ef_4642_9ddf_328ed58f534b["_validate_and_resolve_path()"]
  c970c63b_27bf_364e_6a46_1e5cc38ce38f["FilesystemFileSearchMiddleware"]
  b4e992f2_93ef_4642_9ddf_328ed58f534b -->|defined in| c970c63b_27bf_364e_6a46_1e5cc38ce38f
  99cb0385_d25f_ae58_a625_e8187615e060["__init__()"]
  99cb0385_d25f_ae58_a625_e8187615e060 -->|calls| b4e992f2_93ef_4642_9ddf_328ed58f534b
  c95c91c6_daaf_119c_f394_b216ac96d04e["_ripgrep_search()"]
  c95c91c6_daaf_119c_f394_b216ac96d04e -->|calls| b4e992f2_93ef_4642_9ddf_328ed58f534b
  3f120244_d865_db15_009c_7c3c7671ebd6["_python_search()"]
  3f120244_d865_db15_009c_7c3c7671ebd6 -->|calls| b4e992f2_93ef_4642_9ddf_328ed58f534b
  style b4e992f2_93ef_4642_9ddf_328ed58f534b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/file_search.py lines 235–257

    def _validate_and_resolve_path(self, path: str) -> Path:
        """Validate and resolve a virtual path to filesystem path."""
        # Normalize path
        if not path.startswith("/"):
            path = "/" + path

        # Check for path traversal
        if ".." in path or "~" in path:
            msg = "Path traversal not allowed"
            raise ValueError(msg)

        # Convert virtual path to filesystem path
        relative = path.lstrip("/")
        full_path = (self.root_path / relative).resolve()

        # Ensure path is within root
        try:
            full_path.relative_to(self.root_path)
        except ValueError:
            msg = f"Path outside root directory: {path}"
            raise ValueError(msg) from None

        return full_path

Domain

Subdomains

Frequently Asked Questions

What does _validate_and_resolve_path() do?
_validate_and_resolve_path() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/file_search.py.
Where is _validate_and_resolve_path() defined?
_validate_and_resolve_path() is defined in libs/langchain_v1/langchain/agents/middleware/file_search.py at line 235.
What calls _validate_and_resolve_path()?
_validate_and_resolve_path() is called by 3 function(s): __init__, _python_search, _ripgrep_search.

Analyze Your Own Codebase

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

Try Supermodel Free