stuff.py — langchain Source File
Architecture documentation for stuff.py, a python file in the langchain codebase. 12 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b665d6cc_6c91_59f8_2e5b_85b1b35bfe07["stuff.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> feec1ec4_6917_867b_d228_b134d0ff8099 2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6 17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661 6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 6a98b0a5_5607_0043_2e22_a46a464c2d62 e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> e929cf21_6ab8_6ff3_3765_0d35a099a053 628cbc5d_711f_ac0c_2f53_db992d48d7da["langchain_core.output_parsers"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 628cbc5d_711f_ac0c_2f53_db992d48d7da 435e49bf_bb2e_2016_ead7_0afb9d57ad71["langchain_core.prompts"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 435e49bf_bb2e_2016_ead7_0afb9d57ad71 31eab4ab_7281_1e6c_b17d_12e6ad9de07a["langchain_core.runnables"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 31eab4ab_7281_1e6c_b17d_12e6ad9de07a dd5e7909_a646_84f1_497b_cae69735550e["pydantic"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> dd5e7909_a646_84f1_497b_cae69735550e f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> f85fae70_1011_eaec_151c_4083140ae9e5 f40facfc_f3e4_c00f_e491_0760270cea61["langchain_classic.chains.combine_documents.base"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> f40facfc_f3e4_c00f_e491_0760270cea61 4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"] b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac style b665d6cc_6c91_59f8_2e5b_85b1b35bfe07 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Chain that combines documents by stuffing into context."""
from typing import Any
from langchain_core._api import deprecated
from langchain_core.callbacks import Callbacks
from langchain_core.documents import Document
from langchain_core.language_models import LanguageModelLike
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
from langchain_core.prompts import BasePromptTemplate, format_document
from langchain_core.runnables import Runnable, RunnablePassthrough
from pydantic import ConfigDict, Field, model_validator
from typing_extensions import override
from langchain_classic.chains.combine_documents.base import (
DEFAULT_DOCUMENT_PROMPT,
DEFAULT_DOCUMENT_SEPARATOR,
DOCUMENTS_KEY,
BaseCombineDocumentsChain,
_validate_prompt,
)
from langchain_classic.chains.llm import LLMChain
def create_stuff_documents_chain(
llm: LanguageModelLike,
prompt: BasePromptTemplate,
*,
output_parser: BaseOutputParser | None = None,
document_prompt: BasePromptTemplate | None = None,
document_separator: str = DEFAULT_DOCUMENT_SEPARATOR,
document_variable_name: str = DOCUMENTS_KEY,
) -> Runnable[dict[str, Any], Any]:
r"""Create a chain for passing a list of Documents to a model.
Args:
llm: Language model.
prompt: Prompt template. Must contain input variable `"context"` (override by
setting document_variable), which will be used for passing in the formatted
documents.
output_parser: Output parser. Defaults to `StrOutputParser`.
document_prompt: Prompt used for formatting each document into a string. Input
variables can be "page_content" or any metadata keys that are in all
documents. "page_content" will automatically retrieve the
`Document.page_content`, and all other inputs variables will be
automatically retrieved from the `Document.metadata` dictionary. Default to
a prompt that only contains `Document.page_content`.
document_separator: String separator to use between formatted document strings.
document_variable_name: Variable name to use for the formatted documents in the
prompt. Defaults to `"context"`.
Returns:
An LCEL Runnable. The input is a dictionary that must have a `"context"` key
that maps to a `list[Document]`, and any other input variables expected in the
prompt. The `Runnable` return type depends on `output_parser` used.
Example:
```python
# pip install -U langchain langchain-openai
// ... (232 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- langchain_classic.chains.combine_documents.base
- langchain_classic.chains.llm
- langchain_core._api
- langchain_core.callbacks
- langchain_core.documents
- langchain_core.language_models
- langchain_core.output_parsers
- langchain_core.prompts
- langchain_core.runnables
- pydantic
- typing
- typing_extensions
Source
Frequently Asked Questions
What does stuff.py do?
stuff.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What functions are defined in stuff.py?
stuff.py defines 1 function(s): create_stuff_documents_chain.
What does stuff.py depend on?
stuff.py imports 12 module(s): langchain_classic.chains.combine_documents.base, langchain_classic.chains.llm, langchain_core._api, langchain_core.callbacks, langchain_core.documents, langchain_core.language_models, langchain_core.output_parsers, langchain_core.prompts, and 4 more.
Where is stuff.py in the architecture?
stuff.py is located at libs/langchain/langchain_classic/chains/combine_documents/stuff.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/combine_documents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free