CriteriaResultOutputParser Class — langchain Architecture
Architecture documentation for the CriteriaResultOutputParser class in eval_chain.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4c1c1321_084e_0466_44b4_079bd98a9f6c["CriteriaResultOutputParser"] 8e14b60d_5880_d030_e540_4a171da7ff70["eval_chain.py"] 4c1c1321_084e_0466_44b4_079bd98a9f6c -->|defined in| 8e14b60d_5880_d030_e540_4a171da7ff70 f087cec9_5474_b4cc_687f_61d602354b3f["_type()"] 4c1c1321_084e_0466_44b4_079bd98a9f6c -->|method| f087cec9_5474_b4cc_687f_61d602354b3f 49f6f344_2e44_7f50_49e4_ca93b6f18ebb["parse()"] 4c1c1321_084e_0466_44b4_079bd98a9f6c -->|method| 49f6f344_2e44_7f50_49e4_ca93b6f18ebb
Relationship Graph
Source Code
libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py lines 66–110
class CriteriaResultOutputParser(BaseOutputParser[dict]):
"""A parser for the output of the CriteriaEvalChain."""
@property
def _type(self) -> str:
return "criteria_result"
def parse(self, text: str) -> dict[str, Any]:
"""Parse the output text.
Args:
text: The output text to parse.
Returns:
The parsed output.
"""
verdict = None
score = None
match_last = re.search(r"\s*(Y|N)\s*$", text, re.IGNORECASE)
match_first = re.search(r"^\s*(Y|N)\s*", text, re.IGNORECASE)
match_end = re.search(r"\b(Y|N)\b\s*$", text, re.IGNORECASE)
if match_last:
verdict = match_last.group(1).strip()
text = text[: match_last.start()].strip()
elif match_first:
verdict = match_first.group(1).strip()
text = text[match_first.end() :].strip()
elif match_end:
verdict = match_end.group(1).strip()
text = text[: match_end.start()].strip()
else:
splits = text.strip().rsplit("\n", maxsplit=1)
verdict = splits[-1]
if verdict:
score = (
1 if verdict.upper() == "Y" else (0 if verdict.upper() == "N" else None)
)
return {
"reasoning": text.strip(),
"value": verdict,
"score": score,
}
Source
Frequently Asked Questions
What is the CriteriaResultOutputParser class?
CriteriaResultOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py.
Where is CriteriaResultOutputParser defined?
CriteriaResultOutputParser is defined in libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py at line 66.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free