test_fix.py — langchain Source File
Architecture documentation for test_fix.py, a python file in the langchain codebase. 13 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR c258f556_69a4_6da1_fc5d_59387eebb185["test_fix.py"] c0b5feef_1759_3f2b_62d3_f376e06b863f["datetime"] c258f556_69a4_6da1_fc5d_59387eebb185 --> c0b5feef_1759_3f2b_62d3_f376e06b863f feec1ec4_6917_867b_d228_b134d0ff8099["typing"] c258f556_69a4_6da1_fc5d_59387eebb185 --> feec1ec4_6917_867b_d228_b134d0ff8099 f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] c258f556_69a4_6da1_fc5d_59387eebb185 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 049d69ec_d53a_d170_b6fa_35c395793702["langchain_core.exceptions"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 049d69ec_d53a_d170_b6fa_35c395793702 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 628cbc5d_711f_ac0c_2f53_db992d48d7da["langchain_core.output_parsers"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 628cbc5d_711f_ac0c_2f53_db992d48d7da 4b3dcc0f_d872_0044_39ec_2d289f87f9e6["langchain_core.prompts.prompt"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 4b3dcc0f_d872_0044_39ec_2d289f87f9e6 31eab4ab_7281_1e6c_b17d_12e6ad9de07a["langchain_core.runnables"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 31eab4ab_7281_1e6c_b17d_12e6ad9de07a f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] c258f556_69a4_6da1_fc5d_59387eebb185 --> f85fae70_1011_eaec_151c_4083140ae9e5 6fe7eb9d_3453_f9f0_43a0_6ae621edaf40["langchain_classic.output_parsers.boolean"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 6fe7eb9d_3453_f9f0_43a0_6ae621edaf40 15842c32_7720_d0a3_601d_75425f43295f["langchain_classic.output_parsers.datetime"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 15842c32_7720_d0a3_601d_75425f43295f 8d9303d1_3160_4a5b_3006_12537aaba8e5["langchain_classic.output_parsers.fix"] c258f556_69a4_6da1_fc5d_59387eebb185 --> 8d9303d1_3160_4a5b_3006_12537aaba8e5 d137c2ee_238c_a205_9812_d4052503d886["langchain_classic.output_parsers.prompts"] c258f556_69a4_6da1_fc5d_59387eebb185 --> d137c2ee_238c_a205_9812_d4052503d886 style c258f556_69a4_6da1_fc5d_59387eebb185 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from datetime import datetime as dt
from datetime import timezone
from typing import Any, TypeVar
import pytest
from langchain_core.exceptions import OutputParserException
from langchain_core.messages import AIMessage
from langchain_core.output_parsers import BaseOutputParser
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.runnables import Runnable, RunnableLambda, RunnablePassthrough
from typing_extensions import override
from langchain_classic.output_parsers.boolean import BooleanOutputParser
from langchain_classic.output_parsers.datetime import DatetimeOutputParser
from langchain_classic.output_parsers.fix import OutputFixingParser
from langchain_classic.output_parsers.prompts import NAIVE_FIX_PROMPT
T = TypeVar("T")
class SuccessfulParseAfterRetries(BaseOutputParser[str]):
parse_count: int = 0 # Number of times parse has been called
attemp_count_before_success: int # Number of times to fail before succeeding
@override
def parse(self, *args: Any, **kwargs: Any) -> str:
self.parse_count += 1
if self.parse_count <= self.attemp_count_before_success:
msg = "error"
raise OutputParserException(msg)
return "parsed"
class SuccessfulParseAfterRetriesWithGetFormatInstructions(SuccessfulParseAfterRetries):
def get_format_instructions(self) -> str:
return "instructions"
@pytest.mark.parametrize(
"base_parser",
[
SuccessfulParseAfterRetries(attemp_count_before_success=5),
SuccessfulParseAfterRetriesWithGetFormatInstructions(
attemp_count_before_success=5,
),
],
)
def test_output_fixing_parser_parse(
base_parser: SuccessfulParseAfterRetries,
) -> None:
# preparation
n: int = base_parser.attemp_count_before_success # Success on the (n+1)-th attempt
base_parser = SuccessfulParseAfterRetries(attemp_count_before_success=n)
parser = OutputFixingParser[str](
parser=base_parser,
max_retries=n, # n times to retry, that is, (n+1) times call
retry_chain=RunnablePassthrough(),
legacy=False,
)
# test
// ... (163 more lines)
Domain
Subdomains
Functions
- test_output_fixing_parser_aparse()
- test_output_fixing_parser_aparse_fail()
- test_output_fixing_parser_aparse_with_retry_chain()
- test_output_fixing_parser_from_llm()
- test_output_fixing_parser_output_type()
- test_output_fixing_parser_parse()
- test_output_fixing_parser_parse_fail()
- test_output_fixing_parser_parse_with_retry_chain()
Dependencies
- datetime
- langchain_classic.output_parsers.boolean
- langchain_classic.output_parsers.datetime
- langchain_classic.output_parsers.fix
- langchain_classic.output_parsers.prompts
- langchain_core.exceptions
- langchain_core.messages
- langchain_core.output_parsers
- langchain_core.prompts.prompt
- langchain_core.runnables
- pytest
- typing
- typing_extensions
Source
Frequently Asked Questions
What does test_fix.py do?
test_fix.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_fix.py?
test_fix.py defines 8 function(s): test_output_fixing_parser_aparse, test_output_fixing_parser_aparse_fail, test_output_fixing_parser_aparse_with_retry_chain, test_output_fixing_parser_from_llm, test_output_fixing_parser_output_type, test_output_fixing_parser_parse, test_output_fixing_parser_parse_fail, test_output_fixing_parser_parse_with_retry_chain.
What does test_fix.py depend on?
test_fix.py imports 13 module(s): datetime, langchain_classic.output_parsers.boolean, langchain_classic.output_parsers.datetime, langchain_classic.output_parsers.fix, langchain_classic.output_parsers.prompts, langchain_core.exceptions, langchain_core.messages, langchain_core.output_parsers, and 5 more.
Where is test_fix.py in the architecture?
test_fix.py is located at libs/langchain/tests/unit_tests/output_parsers/test_fix.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain/tests/unit_tests/output_parsers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free