Home / Class/ SelfAskOutputParser Class — langchain Architecture

SelfAskOutputParser Class — langchain Architecture

Architecture documentation for the SelfAskOutputParser class in self_ask.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8b6d0650_41fe_6495_7f78_45ce62999611["SelfAskOutputParser"]
  6701f111_459b_a5ab_36de_5950dae06e0e["AgentOutputParser"]
  8b6d0650_41fe_6495_7f78_45ce62999611 -->|extends| 6701f111_459b_a5ab_36de_5950dae06e0e
  cadd0a52_4d73_7282_dd36_5fc41c66f3b3["self_ask.py"]
  8b6d0650_41fe_6495_7f78_45ce62999611 -->|defined in| cadd0a52_4d73_7282_dd36_5fc41c66f3b3
  671aed8d_3669_bfc7_a6e5_b55bc4bca8af["parse()"]
  8b6d0650_41fe_6495_7f78_45ce62999611 -->|method| 671aed8d_3669_bfc7_a6e5_b55bc4bca8af
  943ed7b7_6a31_ed81_28e9_a6587334e88f["_type()"]
  8b6d0650_41fe_6495_7f78_45ce62999611 -->|method| 943ed7b7_6a31_ed81_28e9_a6587334e88f

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/output_parsers/self_ask.py lines 10–52

class SelfAskOutputParser(AgentOutputParser):
    """Parses self-ask style LLM calls.

    Expects output to be in one of two formats.

    If the output signals that an action should be taken,
    should be in the below format. This will result in an AgentAction
    being returned.

    ```
    Thoughts go here...
    Follow up: what is the temperature in SF?
    ```

    If the output signals that a final answer should be given,
    should be in the below format. This will result in an AgentFinish
    being returned.

    ```
    Thoughts go here...
    So the final answer is: The temperature is 100 degrees
    ```

    """

    followups: Sequence[str] = ("Follow up:", "Followup:")
    finish_string: str = "So the final answer is: "

    @override
    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)

    @property
    def _type(self) -> str:
        return "self_ask"

Frequently Asked Questions

What is the SelfAskOutputParser class?
SelfAskOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/self_ask.py.
Where is SelfAskOutputParser defined?
SelfAskOutputParser is defined in libs/langchain/langchain_classic/agents/output_parsers/self_ask.py at line 10.
What does SelfAskOutputParser extend?
SelfAskOutputParser extends AgentOutputParser.

Analyze Your Own Codebase

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

Try Supermodel Free