configurable_fields() — langchain Function Reference
Architecture documentation for the configurable_fields() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c511db82_36ff_92db_c1e7_da221d062544["configurable_fields()"] 163fcac0_ddd4_a382_5a54_90fc39911022["RunnableSerializable"] c511db82_36ff_92db_c1e7_da221d062544 -->|defined in| 163fcac0_ddd4_a382_5a54_90fc39911022 e2bea970_c5e9_9585_6fa1_e85a5a79ce5e["with_config()"] c511db82_36ff_92db_c1e7_da221d062544 -->|calls| e2bea970_c5e9_9585_6fa1_e85a5a79ce5e style c511db82_36ff_92db_c1e7_da221d062544 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/base.py lines 2614–2670
def configurable_fields(
self, **kwargs: AnyConfigurableField
) -> RunnableSerializable[Input, Output]:
"""Configure particular `Runnable` fields at runtime.
Args:
**kwargs: A dictionary of `ConfigurableField` instances to configure.
Raises:
ValueError: If a configuration key is not found in the `Runnable`.
Returns:
A new `Runnable` with the fields configured.
!!! example
```python
from langchain_core.runnables import ConfigurableField
from langchain_openai import ChatOpenAI
model = ChatOpenAI(max_tokens=20).configurable_fields(
max_tokens=ConfigurableField(
id="output_token_number",
name="Max tokens in the output",
description="The maximum number of tokens in the output",
)
)
# max_tokens = 20
print(
"max_tokens_20: ", model.invoke("tell me something about chess").content
)
# max_tokens = 200
print(
"max_tokens_200: ",
model.with_config(configurable={"output_token_number": 200})
.invoke("tell me something about chess")
.content,
)
```
"""
# Import locally to prevent circular import
from langchain_core.runnables.configurable import ( # noqa: PLC0415
RunnableConfigurableFields,
)
model_fields = type(self).model_fields
for key in kwargs:
if key not in model_fields:
msg = (
f"Configuration key {key} not found in {self}: "
f"available keys are {model_fields.keys()}"
)
raise ValueError(msg)
return RunnableConfigurableFields(default=self, fields=kwargs)
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does configurable_fields() do?
configurable_fields() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is configurable_fields() defined?
configurable_fields() is defined in libs/core/langchain_core/runnables/base.py at line 2614.
What does configurable_fields() call?
configurable_fields() calls 1 function(s): with_config.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free