Home / File/ fix.py — langchain Source File

fix.py — langchain Source File

Architecture documentation for fix.py, a python file in the langchain codebase. 8 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87["fix.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 75137834_4ba7_dc43_7ec5_182c05eceedf
  83d7c7fd_1989_762c_9cf3_cecb50ada22b["langchain_core.output_parsers"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 83d7c7fd_1989_762c_9cf3_cecb50ada22b
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  1f6af6bc_5660_a369_0bfb_4b5c8ed28743["pydantic.py"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 1f6af6bc_5660_a369_0bfb_4b5c8ed28743
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 91721f45_4909_e489_8c1f_084f8bd87145
  79a19a33_3d95_a927_2324_256bde5042eb["langchain_classic.output_parsers.prompts"]
  59284af4_d3b8_96bf_ceb4_0d2c90a20c87 --> 79a19a33_3d95_a927_2324_256bde5042eb
  style 59284af4_d3b8_96bf_ceb4_0d2c90a20c87 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

from typing import Annotated, Any, TypeVar

from langchain_core.exceptions import OutputParserException
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
from langchain_core.prompts import BasePromptTemplate
from langchain_core.runnables import Runnable, RunnableSerializable
from pydantic import SkipValidation
from typing_extensions import TypedDict, override

from langchain_classic.output_parsers.prompts import NAIVE_FIX_PROMPT

T = TypeVar("T")


class OutputFixingParserRetryChainInput(TypedDict, total=False):
    """Input for the retry chain of the OutputFixingParser."""

    instructions: str
    completion: str
    error: str


class OutputFixingParser(BaseOutputParser[T]):
    """Wrap a parser and try to fix parsing errors."""

    @classmethod
    @override
    def is_lc_serializable(cls) -> bool:
        return True

    parser: Annotated[Any, SkipValidation()]
    """The parser to use to parse the output."""
    # Should be an LLMChain but we want to avoid top-level imports from
    # langchain_classic.chains
    retry_chain: Annotated[
        RunnableSerializable[OutputFixingParserRetryChainInput, str] | Any,
        SkipValidation(),
    ]
    """The RunnableSerializable to use to retry the completion (Legacy: LLMChain)."""
    max_retries: int = 1
    """The maximum number of times to retry the parse."""
    legacy: bool = True
    """Whether to use the run or arun method of the retry_chain."""

    @classmethod
    def from_llm(
        cls,
        llm: Runnable,
        parser: BaseOutputParser[T],
        prompt: BasePromptTemplate = NAIVE_FIX_PROMPT,
        max_retries: int = 1,
    ) -> OutputFixingParser[T]:
        """Create an OutputFixingParser from a language model and a parser.

        Args:
            llm: llm to use for fixing
            parser: parser to use for parsing
            prompt: prompt to use for fixing
// ... (97 more lines)

Domain

Subdomains

Dependencies

  • langchain_classic.output_parsers.prompts
  • langchain_core.exceptions
  • langchain_core.output_parsers
  • langchain_core.prompts
  • langchain_core.runnables
  • pydantic.py
  • typing
  • typing_extensions

Frequently Asked Questions

What does fix.py do?
fix.py is a source file in the langchain codebase, written in python. It belongs to the OutputParsing domain, StreamingParsers subdomain.
What does fix.py depend on?
fix.py imports 8 module(s): langchain_classic.output_parsers.prompts, langchain_core.exceptions, langchain_core.output_parsers, langchain_core.prompts, langchain_core.runnables, pydantic.py, typing, typing_extensions.
Where is fix.py in the architecture?
fix.py is located at libs/langchain/langchain_classic/output_parsers/fix.py (domain: OutputParsing, subdomain: StreamingParsers, directory: libs/langchain/langchain_classic/output_parsers).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free