# create_stuff_documents_chain

> **Function** in `langchain_classic`

📖 [View in docs](https://reference.langchain.com/python/langchain-classic/chains/combine_documents/stuff/create_stuff_documents_chain)

Create a chain for passing a list of Documents to a model.

## Signature

```python
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]
```

## Description

**Example:**

```python
# pip install -U langchain langchain-openai

from langchain_openai import ChatOpenAI
from langchain_core.documents import Document
from langchain_core.prompts import ChatPromptTemplate
from langchain_classic.chains.combine_documents import (
    create_stuff_documents_chain,
)

prompt = ChatPromptTemplate.from_messages(
    [("system", "What are everyone's favorite colors:\n\n{context}")]
)
model = ChatOpenAI(model="gpt-3.5-turbo")
chain = create_stuff_documents_chain(model, prompt)

docs = [
    Document(page_content="Jesse loves red but not yellow"),
    Document(
        page_content="Jamal loves green but not as much as he loves orange"
    ),
]

chain.invoke({"context": docs})
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `llm` | `LanguageModelLike` | Yes | Language model. |
| `prompt` | `BasePromptTemplate` | Yes | Prompt template. Must contain input variable `"context"` (override by setting document_variable), which will be used for passing in the formatted documents. |
| `output_parser` | `BaseOutputParser \| None` | No | Output parser. Defaults to `StrOutputParser`. (default: `None`) |
| `document_prompt` | `BasePromptTemplate \| None` | No | 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`. (default: `None`) |
| `document_separator` | `str` | No | String separator to use between formatted document strings. (default: `DEFAULT_DOCUMENT_SEPARATOR`) |
| `document_variable_name` | `str` | No | Variable name to use for the formatted documents in the prompt. Defaults to `"context"`. (default: `DOCUMENTS_KEY`) |

## Returns

`Runnable[dict[str, Any], Any]`

An LCEL Runnable. The input is a dictionary that must have a `"context"` key

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/f0c5a28fa05adcda89aebcb449d897245ab21fa4/libs/langchain/langchain_classic/chains/combine_documents/stuff.py#L25)