Home / File/ retry.py — langchain Source File

retry.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  4d8d636f_d2d5_7fb9_287a_f135606f43b9["retry.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 75137834_4ba7_dc43_7ec5_182c05eceedf
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  83d7c7fd_1989_762c_9cf3_cecb50ada22b["langchain_core.output_parsers"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 83d7c7fd_1989_762c_9cf3_cecb50ada22b
  5b417886_56dd_6afa_13ab_a3cfc1dbcccd["langchain_core.prompt_values"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 5b417886_56dd_6afa_13ab_a3cfc1dbcccd
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  1f6af6bc_5660_a369_0bfb_4b5c8ed28743["pydantic.py"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 1f6af6bc_5660_a369_0bfb_4b5c8ed28743
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  4d8d636f_d2d5_7fb9_287a_f135606f43b9 --> 91721f45_4909_e489_8c1f_084f8bd87145
  style 4d8d636f_d2d5_7fb9_287a_f135606f43b9 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.language_models import BaseLanguageModel
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
from langchain_core.prompt_values import PromptValue
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
from langchain_core.runnables import RunnableSerializable
from pydantic import SkipValidation
from typing_extensions import TypedDict, override

NAIVE_COMPLETION_RETRY = """Prompt:
{prompt}
Completion:
{completion}

Above, the Completion did not satisfy the constraints given in the Prompt.
Please try again:"""

NAIVE_COMPLETION_RETRY_WITH_ERROR = """Prompt:
{prompt}
Completion:
{completion}

Above, the Completion did not satisfy the constraints given in the Prompt.
Details: {error}
Please try again:"""

NAIVE_RETRY_PROMPT = PromptTemplate.from_template(NAIVE_COMPLETION_RETRY)
NAIVE_RETRY_WITH_ERROR_PROMPT = PromptTemplate.from_template(
    NAIVE_COMPLETION_RETRY_WITH_ERROR,
)

T = TypeVar("T")


class RetryOutputParserRetryChainInput(TypedDict):
    """Retry chain input for RetryOutputParser."""

    prompt: str
    completion: str


class RetryWithErrorOutputParserRetryChainInput(TypedDict):
    """Retry chain input for RetryWithErrorOutputParser."""

    prompt: str
    completion: str
    error: str


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

    Does this by passing the original prompt and the completion to another
    LLM, and telling it the completion did not satisfy criteria in the prompt.
    """

// ... (256 more lines)

Domain

Subdomains

Dependencies

  • langchain_core.exceptions
  • langchain_core.language_models
  • langchain_core.output_parsers
  • langchain_core.prompt_values
  • langchain_core.prompts
  • langchain_core.runnables
  • pydantic.py
  • typing
  • typing_extensions

Frequently Asked Questions

What does retry.py do?
retry.py is a source file in the langchain codebase, written in python. It belongs to the OutputParsing domain, StreamingParsers subdomain.
What does retry.py depend on?
retry.py imports 9 module(s): langchain_core.exceptions, langchain_core.language_models, langchain_core.output_parsers, langchain_core.prompt_values, langchain_core.prompts, langchain_core.runnables, pydantic.py, typing, and 1 more.
Where is retry.py in the architecture?
retry.py is located at libs/langchain/langchain_classic/output_parsers/retry.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