Home / Function/ parse() — langchain Function Reference

parse() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6dd245dc_1f98_fe17_cd97_ac711cba89dd["parse()"]
  a11e10b7_0a56_36da_62eb_1707f091d03d["RegexDictParser"]
  6dd245dc_1f98_fe17_cd97_ac711cba89dd -->|defined in| a11e10b7_0a56_36da_62eb_1707f091d03d
  style 6dd245dc_1f98_fe17_cd97_ac711cba89dd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/output_parsers/regex_dict.py lines 23–42

    def parse(self, text: str) -> dict[str, str]:
        """Parse the output of an LLM call."""
        result = {}
        for output_key, expected_format in self.output_key_to_format.items():
            specific_regex = self.regex_pattern.format(re.escape(expected_format))
            matches = re.findall(specific_regex, text)
            if not matches:
                msg = (
                    f"No match found for output key: {output_key} with expected format \
                        {expected_format} on text {text}"
                )
                raise ValueError(msg)
            if len(matches) > 1:
                msg = f"Multiple matches found for output key: {output_key} with \
                        expected format {expected_format} on text {text}"
                raise ValueError(msg)
            if self.no_update_value is not None and matches[0] == self.no_update_value:
                continue
            result[output_key] = matches[0]
        return result

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free