Home / Function/ parse() — langchain Function Reference

parse() — langchain Function Reference

Architecture documentation for the parse() function in llm_router.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  066a3cee_7375_f828_5dd4_9fcf318aa904["parse()"]
  8161be57_0e4f_de90_cda2_8f03a22a4d4a["RouterOutputParser"]
  066a3cee_7375_f828_5dd4_9fcf318aa904 -->|defined in| 8161be57_0e4f_de90_cda2_8f03a22a4d4a
  87ccce0a_1b7e_e8ff_7889_acaf7978975c["_call()"]
  87ccce0a_1b7e_e8ff_7889_acaf7978975c -->|calls| 066a3cee_7375_f828_5dd4_9fcf318aa904
  style 066a3cee_7375_f828_5dd4_9fcf318aa904 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/router/llm_router.py lines 175–196

    def parse(self, text: str) -> dict[str, Any]:
        try:
            expected_keys = ["destination", "next_inputs"]
            parsed = parse_and_check_json_markdown(text, expected_keys)
            if not isinstance(parsed["destination"], str):
                msg = "Expected 'destination' to be a string."
                raise TypeError(msg)
            if not isinstance(parsed["next_inputs"], self.next_inputs_type):
                msg = f"Expected 'next_inputs' to be {self.next_inputs_type}."
                raise TypeError(msg)
            parsed["next_inputs"] = {self.next_inputs_inner_key: parsed["next_inputs"]}
            if (
                parsed["destination"].strip().lower()
                == self.default_destination.lower()
            ):
                parsed["destination"] = None
            else:
                parsed["destination"] = parsed["destination"].strip()
        except Exception as e:
            msg = f"Parsing text\n{text}\n raised following error:\n{e}"
            raise OutputParserException(msg) from e
        return parsed

Subdomains

Called By

Frequently Asked Questions

What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/router/llm_router.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/chains/router/llm_router.py at line 175.
What calls parse()?
parse() is called by 1 function(s): _call.

Analyze Your Own Codebase

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

Try Supermodel Free