Home / Function/ parse() — langchain Function Reference

parse() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  671aed8d_3669_bfc7_a6e5_b55bc4bca8af["parse()"]
  8b6d0650_41fe_6495_7f78_45ce62999611["SelfAskOutputParser"]
  671aed8d_3669_bfc7_a6e5_b55bc4bca8af -->|defined in| 8b6d0650_41fe_6495_7f78_45ce62999611
  style 671aed8d_3669_bfc7_a6e5_b55bc4bca8af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/output_parsers/self_ask.py lines 39–48

    def parse(self, text: str) -> AgentAction | AgentFinish:
        last_line = text.rsplit("\n", maxsplit=1)[-1]
        if not any(follow in last_line for follow in self.followups):
            if self.finish_string not in last_line:
                msg = f"Could not parse output: {text}"
                raise OutputParserException(msg)
            return AgentFinish({"output": last_line[len(self.finish_string) :]}, text)

        after_colon = text.rsplit(":", maxsplit=1)[-1].strip()
        return AgentAction("Intermediate Answer", after_colon, text)

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/self_ask.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/agents/output_parsers/self_ask.py at line 39.

Analyze Your Own Codebase

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

Try Supermodel Free