Skip to content

Fix attribute error for raw tuples in langchain#261

Merged
lmolkova merged 4 commits into
open-telemetry:mainfrom
rads-1996:fix-raw-tuples-input-messages
Jul 14, 2026
Merged

Fix attribute error for raw tuples in langchain#261
lmolkova merged 4 commits into
open-telemetry:mainfrom
rads-1996:fix-raw-tuples-input-messages

Conversation

@rads-1996

@rads-1996 rads-1996 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

to_input_messages assumed every entry in an input messages list was a LangChain BaseMessage. LangGraph/create_agent inputs commonly use raw ("role", text) tuples (e.g. {"messages": [("human", user_input)]}). Accessing .content on such a tuple raised AttributeError("'tuple' object has no attribute 'content'"), which aborted the callback before the invocation could be registered.

image

This exception fired inside the root agent's on_chain_start, before the agent invocation was registered in the invocation manager. As a result, find_nearest_agent could never locate the root agent, so each LangGraph super-step node (model, tools, ...) created its own invoke_agent span, producing duplicate invoke_agent spans instead of one agent span with nested tool/LLM children.

Screenshot 2026-07-13 094210

After Change -

image

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.

  • uv run tox -e py312-test-instrumentation-genai-langchain -- -q
  • uv run tox -e py312-test-instrumentation-genai-langchain-conformance -- -q
  • uv run --python 3.12 tox -e lint-instrumentation-genai-langchain

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the LangChain instrumentation when agent/workflow inputs provide raw ("role", "content") tuples in the messages list, which previously could raise AttributeError and prevent correct agent invocation/span tracking.

Changes:

  • Add a type guard in to_input_messages to avoid accessing .content on non-BaseMessage inputs.
  • Add a unit test covering messages lists containing non-BaseMessage entries.
  • Add a towncrier changelog fragment describing the behavior change.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/utils.py Skips non-BaseMessage entries during input message conversion to avoid runtime errors.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py Adds a regression test around mixed tuple/BaseMessage inputs to make_input_message.
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/261.changed Adds a changelog fragment for the behavior change.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome.

For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question.

Automation flags a PR for human review once every review thread has a reply or is marked as resolved.

Status across open PRs is visible on the pull request dashboard.

@rads-1996
rads-1996 marked this pull request as draft July 13, 2026 17:21
@rads-1996
rads-1996 force-pushed the fix-raw-tuples-input-messages branch from d6bbdb3 to c3d11cb Compare July 13, 2026 18:52
@rads-1996
rads-1996 marked this pull request as ready for review July 13, 2026 18:54
@rads-1996
rads-1996 requested a review from lmolkova July 13, 2026 19:04
@rads-1996
rads-1996 force-pushed the fix-raw-tuples-input-messages branch from f6ced75 to c9f08d6 Compare July 13, 2026 20:22

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY!

@rads-1996
rads-1996 force-pushed the fix-raw-tuples-input-messages branch from c9f08d6 to ac93a87 Compare July 13, 2026 20:55
@lmolkova
lmolkova added this pull request to the merge queue Jul 14, 2026
Merged via the queue into open-telemetry:main with commit b6eef1c Jul 14, 2026
66 checks passed
@rads-1996
rads-1996 deleted the fix-raw-tuples-input-messages branch July 14, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants