RegexDictParser Class — langchain Architecture
Architecture documentation for the RegexDictParser class in regex_dict.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a11e10b7_0a56_36da_62eb_1707f091d03d["RegexDictParser"] 459a1f19_9aa4_cbe4_af1c_c0e7796168c0["regex_dict.py"] a11e10b7_0a56_36da_62eb_1707f091d03d -->|defined in| 459a1f19_9aa4_cbe4_af1c_c0e7796168c0 cb8443bb_1b54_4586_f973_1654af1bf96b["_type()"] a11e10b7_0a56_36da_62eb_1707f091d03d -->|method| cb8443bb_1b54_4586_f973_1654af1bf96b 6dd245dc_1f98_fe17_cd97_ac711cba89dd["parse()"] a11e10b7_0a56_36da_62eb_1707f091d03d -->|method| 6dd245dc_1f98_fe17_cd97_ac711cba89dd
Relationship Graph
Source Code
libs/langchain/langchain_classic/output_parsers/regex_dict.py lines 8–42
class RegexDictParser(BaseOutputParser[dict[str, str]]):
"""Parse the output of an LLM call into a Dictionary using a regex."""
regex_pattern: str = r"{}:\s?([^.'\n']*)\.?"
"""The regex pattern to use to parse the output."""
output_key_to_format: dict[str, str]
"""The keys to use for the output."""
no_update_value: str | None = None
"""The default key to use for the output."""
@property
def _type(self) -> str:
"""Return the type key."""
return "regex_dict_parser"
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
Source
Frequently Asked Questions
What is the RegexDictParser class?
RegexDictParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/regex_dict.py.
Where is RegexDictParser defined?
RegexDictParser is defined in libs/langchain/langchain_classic/output_parsers/regex_dict.py at line 8.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free