RegexParser Class — langchain Architecture
Architecture documentation for the RegexParser class in regex.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 10925ecf_0028_c82d_a03e_3d51aac9fdf7["RegexParser"] ab3b196d_7ab2_81f1_0c38_feb56461e3e0["regex.py"] 10925ecf_0028_c82d_a03e_3d51aac9fdf7 -->|defined in| ab3b196d_7ab2_81f1_0c38_feb56461e3e0 6b76d616_b850_98bd_ad3f_c73f5ef1d7c0["is_lc_serializable()"] 10925ecf_0028_c82d_a03e_3d51aac9fdf7 -->|method| 6b76d616_b850_98bd_ad3f_c73f5ef1d7c0 2390897b_b64f_73c9_3f01_5b41d57446ee["_type()"] 10925ecf_0028_c82d_a03e_3d51aac9fdf7 -->|method| 2390897b_b64f_73c9_3f01_5b41d57446ee d3f9af03_d5d7_b515_1553_90c42c111edf["parse()"] 10925ecf_0028_c82d_a03e_3d51aac9fdf7 -->|method| d3f9af03_d5d7_b515_1553_90c42c111edf
Relationship Graph
Source Code
libs/langchain/langchain_classic/output_parsers/regex.py lines 9–40
class RegexParser(BaseOutputParser[dict[str, str]]):
"""Parse the output of an LLM call using a regex."""
@classmethod
@override
def is_lc_serializable(cls) -> bool:
return True
regex: str
"""The regex to use to parse the output."""
output_keys: list[str]
"""The keys to use for the output."""
default_output_key: str | None = None
"""The default key to use for the output."""
@property
def _type(self) -> str:
"""Return the type key."""
return "regex_parser"
def parse(self, text: str) -> dict[str, str]:
"""Parse the output of an LLM call."""
match = re.search(self.regex, text)
if match:
return {key: match.group(i + 1) for i, key in enumerate(self.output_keys)}
if self.default_output_key is None:
msg = f"Could not parse output: {text}"
raise ValueError(msg)
return {
key: text if key == self.default_output_key else ""
for key in self.output_keys
}
Source
Frequently Asked Questions
What is the RegexParser class?
RegexParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/regex.py.
Where is RegexParser defined?
RegexParser is defined in libs/langchain/langchain_classic/output_parsers/regex.py at line 9.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free