RouterOutputParser Class — langchain Architecture
Architecture documentation for the RouterOutputParser class in llm_router.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8161be57_0e4f_de90_cda2_8f03a22a4d4a["RouterOutputParser"] 12b08e15_dda7_34a6_0911_10fbdd2f2a7b["llm_router.py"] 8161be57_0e4f_de90_cda2_8f03a22a4d4a -->|defined in| 12b08e15_dda7_34a6_0911_10fbdd2f2a7b 066a3cee_7375_f828_5dd4_9fcf318aa904["parse()"] 8161be57_0e4f_de90_cda2_8f03a22a4d4a -->|method| 066a3cee_7375_f828_5dd4_9fcf318aa904
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/router/llm_router.py lines 167–196
class RouterOutputParser(BaseOutputParser[dict[str, str]]):
"""Parser for output of router chain in the multi-prompt chain."""
default_destination: str = "DEFAULT"
next_inputs_type: type = str
next_inputs_inner_key: str = "input"
@override
def parse(self, text: str) -> dict[str, Any]:
try:
expected_keys = ["destination", "next_inputs"]
parsed = parse_and_check_json_markdown(text, expected_keys)
if not isinstance(parsed["destination"], str):
msg = "Expected 'destination' to be a string."
raise TypeError(msg)
if not isinstance(parsed["next_inputs"], self.next_inputs_type):
msg = f"Expected 'next_inputs' to be {self.next_inputs_type}."
raise TypeError(msg)
parsed["next_inputs"] = {self.next_inputs_inner_key: parsed["next_inputs"]}
if (
parsed["destination"].strip().lower()
== self.default_destination.lower()
):
parsed["destination"] = None
else:
parsed["destination"] = parsed["destination"].strip()
except Exception as e:
msg = f"Parsing text\n{text}\n raised following error:\n{e}"
raise OutputParserException(msg) from e
return parsed
Source
Frequently Asked Questions
What is the RouterOutputParser class?
RouterOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/router/llm_router.py.
Where is RouterOutputParser defined?
RouterOutputParser is defined in libs/langchain/langchain_classic/chains/router/llm_router.py at line 167.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free