parse() — langchain Function Reference
Architecture documentation for the parse() function in eval_chain.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 49f6f344_2e44_7f50_49e4_ca93b6f18ebb["parse()"] 4c1c1321_084e_0466_44b4_079bd98a9f6c["CriteriaResultOutputParser"] 49f6f344_2e44_7f50_49e4_ca93b6f18ebb -->|defined in| 4c1c1321_084e_0466_44b4_079bd98a9f6c style 49f6f344_2e44_7f50_49e4_ca93b6f18ebb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py lines 73–110
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,
}
Domain
Subdomains
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py at line 73.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free