Skip to content

bug: propagate_attributes drops non-string metadata instead of coercing (breaks LangGraph integration) #1571

Closed

Description

@nicoyoung

Description

The v4 migration guide states that propagated metadata non-string values are "automatically coerced to strings." However, the actual implementation in propagation.py drops non-string values with a warning instead of coercing them.

This causes noisy warnings when using LangGraph with the Langfuse CallbackHandler, since LangGraph injects internal metadata with non-string values into the RunnableConfig at runtime:

  • langgraph_step → int
  • langgraph_triggers → list
  • langgraph_path → tuple
  • Custom configurable values like max_search_results → int

Expected behavior

Per the v3 → v4 migration guide:

propagated metadata: now dict[str, str] with values limited to 200 characters (was Any). Non-string values are automatically coerced to strings.

Non-string metadata values should be coerced to strings (e.g., via str(value) or json.dumps(value)) rather than dropped.

Actual behavior

_validate_string_value in propagation.py:419-424 drops non-string values and logs a warning:

WARNING:langfuse:Propagated attribute 'metadata.langgraph_step' value is not a string. Dropping value.
WARNING:langfuse:Propagated attribute 'metadata.langgraph_triggers' value is not a string. Dropping value.
WARNING:langfuse:Propagated attribute 'metadata.langgraph_path' value is not a string. Dropping value.

These warnings appear on every LangGraph agent invocation since LangGraph adds these metadata keys automatically.

Suggested fix

In propagation.py, coerce non-string values instead of dropping them:

def _validate_string_value(*, value: str, key: str) -> bool:
    if not isinstance(value, str):
        # Coerce to string instead of dropping
        return True  # after converting: value = str(value)

Or handle this at the metadata processing level in _propagate_attributes by converting non-string values before validation:

if metadata is not None:
    validated_metadata: Dict[str, str] = {}
    for key, value in metadata.items():
        str_value = str(value) if not isinstance(value, str) else value
        if _validate_string_value(value=str_value, key=f"metadata.{key}"):
            validated_metadata[key] = str_value

Environment

  • langfuse Python SDK version: 4.0.0
  • langgraph version: >= 1.0.0
  • Python version: 3.12

Reproduction

from langfuse.langchain import CallbackHandler
from langgraph.graph import StateGraph, MessagesState, START

handler = CallbackHandler()

# Any LangGraph agent will trigger the warnings because LangGraph
# injects langgraph_step (int), langgraph_triggers (list), langgraph_path (tuple)
# into the RunnableConfig metadata during execution.
builder = StateGraph(MessagesState)
# ... build graph ...
graph = builder.compile()

for chunk in graph.stream(
    {"messages": [{"role": "user", "content": "hello"}]},
    config={"callbacks": [handler]},
    stream_mode="values",
):
    pass
# Warnings appear in logs for every graph step

Activity

  1. added a commit that references this issue on Mar 20, 2026
    3ea00c2
  2. ChunkyTortoise commented on Mar 25, 2026

    @ChunkyTortoise

    I'd like to take this. The fix is straightforward — coerce non-string metadata values via str(value) in _propagate_attributes instead of dropping them. I'll submit a PR shortly.

  3. nicoyoung commented on Mar 26, 2026

    @nicoyoung
    Author

    I'd like to take this. The fix is straightforward — coerce non-string metadata values via str(value) in _propagate_attributes instead of dropping them. I'll submit a PR shortly.

    just a note that I opened #1572 alongside this issue with the fix already implemented, including updated type hints (Dict[str, str] → Dict[str, Any]) and docstring corrections. #1575 appears to be a duplicate that was opened after, though it does add a test

  4. vipcxj commented on May 15, 2026

    @vipcxj

    any news?

  5. hassiebp commented on Jun 15, 2026

    @hassiebp
    Collaborator

    Fixed in #1709, thanks for raising this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions