Home / Function/ _format_grep_results() — langchain Function Reference

_format_grep_results() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  2fea0616_83be_c78c_1ec3_10dc4ee6b2a3["_format_grep_results()"]
  90afd8f3_1e0a_8505_387a_6cda18a008c3["StateFileSearchMiddleware"]
  2fea0616_83be_c78c_1ec3_10dc4ee6b2a3 -->|defined in| 90afd8f3_1e0a_8505_387a_6cda18a008c3
  9c9a2eda_be6c_5f6f_9a0a_3f3e5575dc2e["_handle_grep_search()"]
  9c9a2eda_be6c_5f6f_9a0a_3f3e5575dc2e -->|calls| 2fea0616_83be_c78c_1ec3_10dc4ee6b2a3
  style 2fea0616_83be_c78c_1ec3_10dc4ee6b2a3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/file_search.py lines 322–349

    def _format_grep_results(
        self,
        results: dict[str, list[tuple[int, str]]],
        output_mode: str,
    ) -> str:
        """Format grep results based on output mode."""
        if output_mode == "files_with_matches":
            # Just return file paths
            return "\n".join(sorted(results.keys()))

        if output_mode == "content":
            # Return file:line:content format
            lines = []
            for file_path in sorted(results.keys()):
                for line_num, line in results[file_path]:
                    lines.append(f"{file_path}:{line_num}:{line}")
            return "\n".join(lines)

        if output_mode == "count":
            # Return file:count format
            lines = []
            for file_path in sorted(results.keys()):
                count = len(results[file_path])
                lines.append(f"{file_path}:{count}")
            return "\n".join(lines)

        # Default to files_with_matches
        return "\n".join(sorted(results.keys()))

Domain

Subdomains

Frequently Asked Questions

What does _format_grep_results() do?
_format_grep_results() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py.
Where is _format_grep_results() defined?
_format_grep_results() is defined in libs/partners/anthropic/langchain_anthropic/middleware/file_search.py at line 322.
What calls _format_grep_results()?
_format_grep_results() is called by 1 function(s): _handle_grep_search.

Analyze Your Own Codebase

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

Try Supermodel Free