From 9f5f3fb35eac99491391ed1fc337c0f7fe254352 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Thu, 2 Apr 2026 11:05:17 -0700 Subject: [PATCH] Revert "chore: update configurable metadata" (#7393) Reverts langchain-ai/langgraph#7367 --- libs/langgraph/langgraph/_internal/_config.py | 20 ++++++++++++++++++- libs/langgraph/tests/test_utils.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libs/langgraph/langgraph/_internal/_config.py b/libs/langgraph/langgraph/_internal/_config.py index fe1aad509..4e9c5aa92 100644 --- a/libs/langgraph/langgraph/_internal/_config.py +++ b/libs/langgraph/langgraph/_internal/_config.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections import ChainMap -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from os import getenv from typing import Any, cast @@ -308,4 +308,22 @@ def ensure_config(*configs: RunnableConfig | None) -> RunnableConfig: for k, v in config.items(): if _is_not_empty(v) and k not in CONFIG_KEYS: empty[CONF][k] = v + _empty_metadata = empty["metadata"] + for key, value in empty[CONF].items(): + if _exclude_as_metadata(key, value, _empty_metadata): + continue + _empty_metadata[key] = value return empty + + +_OMIT = ("key", "token", "secret", "password", "auth") + + +def _exclude_as_metadata(key: str, value: Any, metadata: Mapping[str, Any]) -> bool: + key_lower = key.casefold() + return ( + key.startswith("__") + or not isinstance(value, (str, int, float, bool)) + or key in metadata + or any(substr in key_lower for substr in _OMIT) + ) diff --git a/libs/langgraph/tests/test_utils.py b/libs/langgraph/tests/test_utils.py index e841d7b0a..c8d2bbc71 100644 --- a/libs/langgraph/tests/test_utils.py +++ b/libs/langgraph/tests/test_utils.py @@ -312,7 +312,7 @@ def test_configurable_metadata(): }, "metadata": {"nooverride": 18}, } - expected = {"nooverride"} + expected = {"includeme", "andme", "nooverride"} merged = ensure_config(config) metadata = merged["metadata"] assert metadata.keys() == expected