Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  30fc102e_3f63_e306_80b0_fecb9b2341b7["base.py"]
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> feec1ec4_6917_867b_d228_b134d0ff8099
  2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6
  17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  435e49bf_bb2e_2016_ead7_0afb9d57ad71["langchain_core.prompts"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 435e49bf_bb2e_2016_ead7_0afb9d57ad71
  9a0fc770_8c3f_14bc_3c7d_37852927778e["langchain_classic.chains.base"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 9a0fc770_8c3f_14bc_3c7d_37852927778e
  1c769616_64e9_39f1_7949_bf4af20faa1c["langchain_classic.chains.constitutional_ai.models"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 1c769616_64e9_39f1_7949_bf4af20faa1c
  14543b30_1a5d_5b04_d92e_68a7f27d9d8f["langchain_classic.chains.constitutional_ai.principles"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 14543b30_1a5d_5b04_d92e_68a7f27d9d8f
  587fbbb0_aa88_c07a_e7e9_d165e20dbf70["langchain_classic.chains.constitutional_ai.prompts"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 587fbbb0_aa88_c07a_e7e9_d165e20dbf70
  4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"]
  30fc102e_3f63_e306_80b0_fecb9b2341b7 --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac
  style 30fc102e_3f63_e306_80b0_fecb9b2341b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Chain for applying constitutional principles to the outputs of another chain."""

from typing import Any

from langchain_core._api import deprecated
from langchain_core.callbacks import CallbackManagerForChainRun
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate

from langchain_classic.chains.base import Chain
from langchain_classic.chains.constitutional_ai.models import ConstitutionalPrinciple
from langchain_classic.chains.constitutional_ai.principles import PRINCIPLES
from langchain_classic.chains.constitutional_ai.prompts import (
    CRITIQUE_PROMPT,
    REVISION_PROMPT,
)
from langchain_classic.chains.llm import LLMChain


@deprecated(
    since="0.2.13",
    message=(
        "This class is deprecated and will be removed in langchain 1.0. "
        "See API reference for replacement: "
        "https://api.python.langchain.com/en/latest/chains/langchain.chains.constitutional_ai.base.ConstitutionalChain.html"
    ),
    removal="1.0",
)
class ConstitutionalChain(Chain):
    r'''Chain for applying constitutional principles.

    !!! note
        This class is deprecated. See below for a replacement implementation using
        LangGraph. The benefits of this implementation are:

        - Uses LLM tool calling features instead of parsing string responses;
        - Support for both token-by-token and step-by-step streaming;
        - Support for checkpointing and memory of chat history;
        - Easier to modify or extend (e.g., with additional tools, structured responses, etc.)

        Install LangGraph with:

        ```bash
        pip install -U langgraph
        ```

        ```python
        from typing import List, Optional, Tuple

        from langchain_classic.chains.constitutional_ai.prompts import (
            CRITIQUE_PROMPT,
            REVISION_PROMPT,
        )
        from langchain_classic.chains.constitutional_ai.models import ConstitutionalPrinciple
        from langchain_core.output_parsers import StrOutputParser
        from langchain_core.prompts import ChatPromptTemplate
        from langchain_openai import ChatOpenAI
        from langgraph.graph import END, START, StateGraph
        from typing_extensions import Annotated, TypedDict

// ... (273 more lines)

Subdomains

Dependencies

  • langchain_classic.chains.base
  • langchain_classic.chains.constitutional_ai.models
  • langchain_classic.chains.constitutional_ai.principles
  • langchain_classic.chains.constitutional_ai.prompts
  • langchain_classic.chains.llm
  • langchain_core._api
  • langchain_core.callbacks
  • langchain_core.language_models
  • langchain_core.prompts
  • typing

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What does base.py depend on?
base.py imports 10 module(s): langchain_classic.chains.base, langchain_classic.chains.constitutional_ai.models, langchain_classic.chains.constitutional_ai.principles, langchain_classic.chains.constitutional_ai.prompts, langchain_classic.chains.llm, langchain_core._api, langchain_core.callbacks, langchain_core.language_models, and 2 more.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/chains/constitutional_ai/base.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/constitutional_ai).

Analyze Your Own Codebase

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

Try Supermodel Free