Skip to content

The agent engineering platform.

docs: Improve docstring for Runnable bind method (#19659)

jhicks2306bcb8ab5216ea
diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py
index b9e4e37fd7..78188f2e6e 100644
--- a/libs/core/langchain_core/runnables/base.py
+++ b/libs/core/langchain_core/runnables/base.py
@@ -1336,6 +1336,37 @@ class Runnable(Generic[Input, Output], ABC):
def bind(self, **kwargs: Any) -> Runnable[Input, Output]:
"""
Bind arguments to a Runnable, returning a new Runnable.
+
+ Useful when a runnable in a chain requires an argument that is not
+ in the output of the previous runnable or included in the user input.
+
+ Example:
+
+ .. code-block:: python
+
+ from langchain_community.chat_models import ChatOllama
+ from langchain_core.output_parsers import StrOutputParser
+
+ llm = ChatOllama(model='llama2')
+
+ # Without bind.
+ chain = (
+ llm
+ | StrOutputParser()
+ )
+
+ chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
+ # Output is 'One two three four five.'
+
+ # With bind.
+ chain = (
+ llm.bind(stop=["three"])
+ | StrOutputParser()
+ )
+
+ chain.invoke("Repeat quoted words exactly: 'One two three four five.'")
+ # Output is 'One two'
+
"""
return RunnableBinding(bound=self, kwargs=kwargs, config={})