Home / Function/ map() — langchain Function Reference

map() — langchain Function Reference

Architecture documentation for the map() function in string_run_evaluator.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb["map()"]
  3ac90b6f_675b_ff6a_04b3_989d183b1348["ChainStringRunMapper"]
  b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb -->|defined in| 3ac90b6f_675b_ff6a_04b3_989d183b1348
  eeef200b_d96b_43d0_3074_30604390fe0c["map()"]
  eeef200b_d96b_43d0_3074_30604390fe0c -->|calls| b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb
  299b611e_fb70_d4ca_6dcc_c6031a8162d9["_get_key()"]
  b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb -->|calls| 299b611e_fb70_d4ca_6dcc_c6031a8162d9
  eeef200b_d96b_43d0_3074_30604390fe0c["map()"]
  b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb -->|calls| eeef200b_d96b_43d0_3074_30604390fe0c
  style b8c4bf91_87d7_ce69_1350_1bcdf1bccbbb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py lines 179–211

    def map(self, run: Run) -> dict[str, str]:
        """Maps the Run to a dictionary."""
        if not run.outputs:
            msg = (
                f"Run with ID {run.id} lacks outputs required for evaluation."
                " Ensure the Run has valid outputs."
            )
            raise ValueError(msg)
        if self.input_key is not None and self.input_key not in run.inputs:
            msg = (
                f"Run with ID {run.id} is missing the expected input key"
                f" '{self.input_key}'.\nAvailable input keys in this Run"
                f"  are: {run.inputs.keys()}.\nAdjust the evaluator's"
                f" input_key or ensure your input data includes key"
                f" '{self.input_key}'."
            )
            raise ValueError(msg)
        if self.prediction_key is not None and self.prediction_key not in run.outputs:
            available_keys = ", ".join(run.outputs.keys())
            msg = (
                f"Run with ID {run.id} doesn't have the expected prediction key"
                f" '{self.prediction_key}'. Available prediction keys in this Run are:"
                f" {available_keys}. Adjust the evaluator's prediction_key or"
                " ensure the Run object's outputs the expected key."
            )
            raise ValueError(msg)

        input_ = self._get_key(run.inputs, self.input_key, "input")
        prediction = self._get_key(run.outputs, self.prediction_key, "prediction")
        return {
            "input": input_,
            "prediction": prediction,
        }

Domain

Subdomains

Called By

Frequently Asked Questions

What does map() do?
map() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py.
Where is map() defined?
map() is defined in libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py at line 179.
What does map() call?
map() calls 2 function(s): _get_key, map.
What calls map()?
map() is called by 1 function(s): map.

Analyze Your Own Codebase

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

Try Supermodel Free