Home / Function/ parse_with_prompt() — langchain Function Reference

parse_with_prompt() — langchain Function Reference

Architecture documentation for the parse_with_prompt() function in retry.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ea8d4ab5_903d_16fa_398f_656ae160bfd8["parse_with_prompt()"]
  056612cb_8291_0c46_ab1b_ac10284862d6["RetryOutputParser"]
  ea8d4ab5_903d_16fa_398f_656ae160bfd8 -->|defined in| 056612cb_8291_0c46_ab1b_ac10284862d6
  00b0c9ad_c753_b223_9358_1381afe521f7["parse_with_prompt()"]
  00b0c9ad_c753_b223_9358_1381afe521f7 -->|calls| ea8d4ab5_903d_16fa_398f_656ae160bfd8
  00b0c9ad_c753_b223_9358_1381afe521f7["parse_with_prompt()"]
  ea8d4ab5_903d_16fa_398f_656ae160bfd8 -->|calls| 00b0c9ad_c753_b223_9358_1381afe521f7
  b6353c05_1a1b_3d84_4db8_e8697219d234["parse()"]
  ea8d4ab5_903d_16fa_398f_656ae160bfd8 -->|calls| b6353c05_1a1b_3d84_4db8_e8697219d234
  style ea8d4ab5_903d_16fa_398f_656ae160bfd8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/output_parsers/retry.py lines 97–130

    def parse_with_prompt(self, completion: str, prompt_value: PromptValue) -> T:
        """Parse the output of an LLM call using a wrapped parser.

        Args:
            completion: The chain completion to parse.
            prompt_value: The prompt to use to parse the completion.

        Returns:
            The parsed completion.
        """
        retries = 0

        while retries <= self.max_retries:
            try:
                return self.parser.parse(completion)
            except OutputParserException:
                if retries == self.max_retries:
                    raise
                retries += 1
                if self.legacy and hasattr(self.retry_chain, "run"):
                    completion = self.retry_chain.run(
                        prompt=prompt_value.to_string(),
                        completion=completion,
                    )
                else:
                    completion = self.retry_chain.invoke(
                        {
                            "prompt": prompt_value.to_string(),
                            "completion": completion,
                        },
                    )

        msg = "Failed to parse"
        raise OutputParserException(msg)

Domain

Subdomains

Frequently Asked Questions

What does parse_with_prompt() do?
parse_with_prompt() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/retry.py.
Where is parse_with_prompt() defined?
parse_with_prompt() is defined in libs/langchain/langchain_classic/output_parsers/retry.py at line 97.
What does parse_with_prompt() call?
parse_with_prompt() calls 2 function(s): parse, parse_with_prompt.
What calls parse_with_prompt()?
parse_with_prompt() is called by 1 function(s): parse_with_prompt.

Analyze Your Own Codebase

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

Try Supermodel Free