Skip to content

[bug] Python LangChain 1.0 instrumentation error in _extract_message_role(): expected list, found <class 'NoneType'> #2426

@scribu

Description

@scribu

Describe the bug

ERROR:openinference.instrumentation.langchain._tracer:Failed to get attribute.
Traceback (most recent call last):
  File "/Users/scribu/my-project/.venv/lib/python3.13/site-packages/openinference/instrumentation/langchain/_tracer.py", line 324, in wrapper
    yield from wrapped(*args, **kwargs)
  File "/Users/scribu/my-project/.venv/lib/python3.13/site-packages/openinference/instrumentation/langchain/_tracer.py", line 574, in _extract_message_role
    assert isinstance(id_, List), f"expected list, found {type(id_)}"
           ~~~~~~~~~~^^^^^^^^^^^
AssertionError: expected list, found <class 'NoneType'>

Steps To Reproduce

Pass a raw dict as a message to a Langchain agent:

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

model = ChatOpenAI()

agent = create_agent(model=model)

# This works fine
# message = HumanMessage(content="What's the weather in London?")

# This throws the assertion error
message = {"role": "user", "content": "What's the weather in London?"}

result = agent.invoke({"messages": [message]})

output = result["messages"][-1].content

print(output)

Note that using HumanMessage() instead of a raw dict works

Versions

openai==2.7.2
langchain==1.0.5
langchain-openai==1.0.2
openinference-instrumentation==0.1.42
openinference-instrumentation-langchain==0.1.54

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions