BooleanOutputParser Class — langchain Architecture
Architecture documentation for the BooleanOutputParser class in boolean.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD da968a10_fe6d_3b39_b567_42129c1c66a4["BooleanOutputParser"] 27db5a2b_caca_e6cb_92f1_a74e1316573e["boolean.py"] da968a10_fe6d_3b39_b567_42129c1c66a4 -->|defined in| 27db5a2b_caca_e6cb_92f1_a74e1316573e 461fb1ed_a3c7_c638_a529_699f63c96a8f["parse()"] da968a10_fe6d_3b39_b567_42129c1c66a4 -->|method| 461fb1ed_a3c7_c638_a529_699f63c96a8f a28a5ff0_9ef7_823c_145d_9c0ae3e728da["_type()"] da968a10_fe6d_3b39_b567_42129c1c66a4 -->|method| a28a5ff0_9ef7_823c_145d_9c0ae3e728da
Relationship Graph
Source Code
libs/langchain/langchain_classic/output_parsers/boolean.py lines 6–54
class BooleanOutputParser(BaseOutputParser[bool]):
"""Parse the output of an LLM call to a boolean."""
true_val: str = "YES"
"""The string value that should be parsed as True."""
false_val: str = "NO"
"""The string value that should be parsed as False."""
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)
@property
def _type(self) -> str:
"""Snake-case string identifier for an output parser type."""
return "boolean_output_parser"
Source
Frequently Asked Questions
What is the BooleanOutputParser class?
BooleanOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/boolean.py.
Where is BooleanOutputParser defined?
BooleanOutputParser is defined in libs/langchain/langchain_classic/output_parsers/boolean.py at line 6.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free