test_mrkl_output_parser.py — langchain Source File
Architecture documentation for test_mrkl_output_parser.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 3173c076_30f3_91af_3ede_46a6c01ad22a["test_mrkl_output_parser.py"] 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 3173c076_30f3_91af_3ede_46a6c01ad22a --> 120e2591_3e15_b895_72b6_cb26195e40a6 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"] 3173c076_30f3_91af_3ede_46a6c01ad22a --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b 75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"] 3173c076_30f3_91af_3ede_46a6c01ad22a --> 75137834_4ba7_dc43_7ec5_182c05eceedf 57c94080_afd4_14d9_92df_eefcc194be4b["langchain_classic.agents.mrkl.output_parser"] 3173c076_30f3_91af_3ede_46a6c01ad22a --> 57c94080_afd4_14d9_92df_eefcc194be4b style 3173c076_30f3_91af_3ede_46a6c01ad22a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import pytest
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.exceptions import OutputParserException
from langchain_classic.agents.mrkl.output_parser import (
MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE,
MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE,
MRKLOutputParser,
)
mrkl_output_parser = MRKLOutputParser()
def test_valid_action_and_action_input_parse() -> None:
llm_output = """I can use the `foo` tool to achieve the goal.
Action: foo
Action Input: bar"""
agent_action: AgentAction = mrkl_output_parser.parse(llm_output) # type: ignore[assignment]
assert agent_action.tool == "foo"
assert agent_action.tool_input == "bar"
def test_valid_final_answer_parse() -> None:
llm_output = """Final Answer: The best pizza to eat is margaritta """
agent_finish: AgentFinish = mrkl_output_parser.parse(llm_output) # type: ignore[assignment]
assert (
agent_finish.return_values.get("output")
== "The best pizza to eat is margaritta"
)
def test_missing_action() -> None:
llm_output = """I can use the `foo` tool to achieve the goal."""
with pytest.raises(OutputParserException) as exception_info:
mrkl_output_parser.parse(llm_output)
assert (
exception_info.value.observation == MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE
)
def test_missing_action_input() -> None:
llm_output = """I can use the `foo` tool to achieve the goal.
Action: foo"""
with pytest.raises(OutputParserException) as exception_info:
mrkl_output_parser.parse(llm_output)
assert (
exception_info.value.observation
== MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE
)
def test_final_answer_before_parsable_action() -> None:
llm_output = """Final Answer: The best pizza to eat is margaritta
Action: foo
Action Input: bar
"""
agent_finish: AgentFinish = mrkl_output_parser.parse(llm_output) # type: ignore[assignment]
assert (
agent_finish.return_values.get("output")
== "The best pizza to eat is margaritta"
)
def test_final_answer_after_parsable_action() -> None:
llm_output = """
Observation: I can use the `foo` tool to achieve the goal.
Action: foo
Action Input: bar
Final Answer: The best pizza to eat is margaritta
"""
with pytest.raises(OutputParserException) as exception_info:
mrkl_output_parser.parse(llm_output)
assert (
"Parsing LLM output produced both a final answer and a parse-able action"
in exception_info.value.args[0]
)
Domain
Subdomains
Functions
Dependencies
- langchain_classic.agents.mrkl.output_parser
- langchain_core.agents
- langchain_core.exceptions
- pytest
Source
Frequently Asked Questions
What does test_mrkl_output_parser.py do?
test_mrkl_output_parser.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_mrkl_output_parser.py?
test_mrkl_output_parser.py defines 6 function(s): test_final_answer_after_parsable_action, test_final_answer_before_parsable_action, test_missing_action, test_missing_action_input, test_valid_action_and_action_input_parse, test_valid_final_answer_parse.
What does test_mrkl_output_parser.py depend on?
test_mrkl_output_parser.py imports 4 module(s): langchain_classic.agents.mrkl.output_parser, langchain_core.agents, langchain_core.exceptions, pytest.
Where is test_mrkl_output_parser.py in the architecture?
test_mrkl_output_parser.py is located at libs/langchain/tests/unit_tests/agents/test_mrkl_output_parser.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/agents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free