Home / Function/ ensure_config() — langchain Function Reference

ensure_config() — langchain Function Reference

Architecture documentation for the ensure_config() function in config.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cdd8615f_f126_a0bd_773d_743c2cdb5aaa["ensure_config()"]
  217fac2f_15f6_1c1e_2b6e_1dae6dfdea14["config.py"]
  cdd8615f_f126_a0bd_773d_743c2cdb5aaa -->|defined in| 217fac2f_15f6_1c1e_2b6e_1dae6dfdea14
  849ca24e_ae2b_f5c9_49cf_256b45cd8833["get_config_list()"]
  849ca24e_ae2b_f5c9_49cf_256b45cd8833 -->|calls| cdd8615f_f126_a0bd_773d_743c2cdb5aaa
  ca40928c_5f65_aced_42f4_97bbe3d61175["patch_config()"]
  ca40928c_5f65_aced_42f4_97bbe3d61175 -->|calls| cdd8615f_f126_a0bd_773d_743c2cdb5aaa
  e950e389_2fcb_e1d8_6ed8_a32004b94262["merge_configs()"]
  e950e389_2fcb_e1d8_6ed8_a32004b94262 -->|calls| cdd8615f_f126_a0bd_773d_743c2cdb5aaa
  style cdd8615f_f126_a0bd_773d_743c2cdb5aaa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/config.py lines 216–266

def ensure_config(config: RunnableConfig | None = None) -> RunnableConfig:
    """Ensure that a config is a dict with all keys present.

    Args:
        config: The config to ensure.

    Returns:
        The ensured config.
    """
    empty = RunnableConfig(
        tags=[],
        metadata={},
        callbacks=None,
        recursion_limit=DEFAULT_RECURSION_LIMIT,
        configurable={},
    )
    if var_config := var_child_runnable_config.get():
        empty.update(
            cast(
                "RunnableConfig",
                {
                    k: v.copy() if k in COPIABLE_KEYS else v  # type: ignore[attr-defined]
                    for k, v in var_config.items()
                    if v is not None
                },
            )
        )
    if config is not None:
        empty.update(
            cast(
                "RunnableConfig",
                {
                    k: v.copy() if k in COPIABLE_KEYS else v  # type: ignore[attr-defined]
                    for k, v in config.items()
                    if v is not None and k in CONFIG_KEYS
                },
            )
        )
    if config is not None:
        for k, v in config.items():
            if k not in CONFIG_KEYS and v is not None:
                empty["configurable"][k] = v
    for key, value in empty.get("configurable", {}).items():
        if (
            not key.startswith("__")
            and isinstance(value, (str, int, float, bool))
            and key not in empty["metadata"]
            and key != "api_key"
        ):
            empty["metadata"][key] = value
    return empty

Domain

Subdomains

Frequently Asked Questions

What does ensure_config() do?
ensure_config() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/config.py.
Where is ensure_config() defined?
ensure_config() is defined in libs/core/langchain_core/runnables/config.py at line 216.
What calls ensure_config()?
ensure_config() is called by 3 function(s): get_config_list, merge_configs, patch_config.

Analyze Your Own Codebase

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

Try Supermodel Free