parse() — langchain Function Reference
Architecture documentation for the parse() function in boolean.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 461fb1ed_a3c7_c638_a529_699f63c96a8f["parse()"] da968a10_fe6d_3b39_b567_42129c1c66a4["BooleanOutputParser"] 461fb1ed_a3c7_c638_a529_699f63c96a8f -->|defined in| da968a10_fe6d_3b39_b567_42129c1c66a4 style 461fb1ed_a3c7_c638_a529_699f63c96a8f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/output_parsers/boolean.py lines 14–49
def parse(self, text: str) -> bool:
"""Parse the output of an LLM call to a boolean.
Args:
text: output of a language model
Returns:
boolean
"""
regexp = rf"\b({self.true_val}|{self.false_val})\b"
truthy = {
val.upper()
for val in re.findall(regexp, text, flags=re.IGNORECASE | re.MULTILINE)
}
if self.true_val.upper() in truthy:
if self.false_val.upper() in truthy:
msg = (
f"Ambiguous response. Both {self.true_val} and {self.false_val} "
f"in received: {text}."
)
raise ValueError(msg)
return True
if self.false_val.upper() in truthy:
if self.true_val.upper() in truthy:
msg = (
f"Ambiguous response. Both {self.true_val} and {self.false_val} "
f"in received: {text}."
)
raise ValueError(msg)
return False
msg = (
f"BooleanOutputParser expected output value to include either "
f"{self.true_val} or {self.false_val}. Received {text}."
)
raise ValueError(msg)
Domain
Subdomains
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/boolean.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/output_parsers/boolean.py at line 14.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free