Skip to content

fix(web): preserve chat message role titles on non-generation observations (#19198) - #19210

Open
ghazy2001 wants to merge 2 commits into
langfuse:mainfrom
ghazy2001:fix/chat-message-role-titles-19198
Open

ghazy2001 wants to merge 2 commits into
langfuse:mainfrom
ghazy2001:fix/chat-message-role-titles-19198

Conversation

@ghazy2001

@ghazy2001 ghazy2001 commented Oct 22, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #19198

Context & Problem

In #18787, IOPreviewPretty.tsx introduced:

const titleBySide = observationType !== undefined && observationType !== 'GENERATION';

This was intended to display Input / Output headers for tool/span I/O containing arbitrary JSON or raw strings instead of defaulting to User / Assistant.

However, when multi-agent workflows or chat interactions are logged as SPAN, AGENT, or TOOL observations, this logic caused all messages—including assistant and system messages—to be titled Input because titleBySide was unconditionally true for any non-GENERATION observation.

Solution

  1. Chat Conversation Detection (chatMessageUtils.ts):
    • Added isExplicitChatMessage(value) to check whether raw data contains chat message structures (array of message objects with role / tool_calls, or objects with messages array).
    • Added isChatConversation({ input, output, messages, inputMessageCount }) to identify if an observation represents a chat dialogue (multi-turn messages, explicit assistant/system/tool roles in input, or chat message payloads).
  2. Preserve Role Titles in IOPreviewPretty.tsx:
    • titleBySide is now observationType !== undefined && observationType !== 'GENERATION' && !isChat.
    • Tool/span observations with regular JSON or plain text continue to show Input / Output as intended by fix(web): label non-chat input and output as Input and Output #18787.
    • Observations containing genuine chat messages preserve their role titles (User, Assistant, System, Tool).
  3. Defense-in-depth in ChatMessageList.tsx:
    • Ensures that even in side-titled contexts, non-output messages with assistant or system roles are never labeled Input.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Mandatory Tasks

  • Make sure you have self-reviewed the code.

Tests & Verification

  • Unit Tests Added:
    • Added 10 unit test cases in web/src/features/traces/fns/chatMessageUtils.clienttest.ts covering:
      • Chat message arrays with role
      • Objects with tool_calls
      • Objects containing messages arrays
      • Single message objects with valid roles
      • Non-chat JSON objects and plain strings (ensuring titleBySide still applies to arbitrary tool I/O)
      • Multi-turn conversation detection
      • Input containing assistant or system messages
  • Test Results:
    • Ran bun test web/src/features/traces/fns/chatMessageUtils.clienttest.ts: 41/41 passing (22ms).

(Available for further frontend/observability contributions and contractor work: [email protected])

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@greptile-apps greptile-apps Bot 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.

Greptile has paused reviews on this repository — it used its 1000 free open-source review credits for this billing period. Reviews resume automatically on October 29. To continue before then, an organization admin can keep reviews running past the free credits — those bill as normal usage.

@CLAassistant

CLAassistant commented Oct 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cijaaimee

Copy link
Copy Markdown

Hello! Thanks for looking into my issue so quickly 😄
Not sure if this PR tackles this as well, but some of our usecases have "mixed" I/O. That is, an observation where the input is a conversation, but the output is not (or the other way around). For example, a guardrails span: the output in this case is just plain text. In this case, ideally:

  • the input would be labelledas chat messages: "System", "User", "Assistant"...
  • the output would still be labeled "Output".
    Is this already the case, or does this PR require both input and output to be chat messages for it to be detected?

@ghazy2001

Copy link
Copy Markdown
Author

Hi @cijaaimee,

Great point! I've just updated the PR to support independent per-side role titling for mixed I/O cases exactly as you described.

Specifically:

  • isInputChat and isOutputChat are now evaluated independently.
  • For mixed I/O observations (e.g. guardrails spans with a chat conversation input and a plain-text string output):
    • The input messages keep their respective chat role headers (\System, \User, \Assistant, \Tool).
    • The output continues to display the \Output\ header.
  • Likewise, if the input is raw text/parameters and the output is a chat response, the input is titled \Input\ while the output retains its role header (\Assistant).
  • Non-chat tool observations continue to show \Input\ / \Output\ on both sides as intended by fix(web): label non-chat input and output as Input and Output #18787.

Added comprehensive unit tests covering the independent side detection and mixed I/O scenarios (50/50 passing).

@langfuse-ai-gate-approver

Copy link
Copy Markdown

AI review gate — Waiting for AI review

  • Cursor Bugbot has not posted a review on this commit yet.

What to do:

  • Nothing to do yet if the review is running. The gate turns green when it finishes clean.
  • No review showing up? Post bugbot run as a new top-level PR comment. If that does nothing, Bugbot is probably not enabled for this repository: ask a repository administrator.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then comment /ai-gate check on the pull request. Their approval stands in for the AI review (a new push needs a new approval).

Configuration: the repository's .github/ai-gate.yml on the base branch (the defaults without one).

History (latest 5 heads, newest first)

  • 54d5ad195648 gate pending — Waiting for AI review

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: chat messages on non-GENERATION observations are titled "Input"/"Output" instead of by role

3 participants