Skip to content

fix(langchain): fallback to exception class name when error message is empty - #2093

Open
viliamgonda wants to merge 1 commit into
langfuse:mainfrom
viliamgonda:fix/langchain-callback-empty-error-status-message
Open

viliamgonda wants to merge 1 commit into
langfuse:mainfrom
viliamgonda:fix/langchain-callback-empty-error-status-message

Conversation

@viliamgonda

@viliamgonda viliamgonda commented Nov 3, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes langfuse/langfuse#19599

In LangchainCallbackHandler._get_error_level_and_status_message, ordinary exceptions only returned str(error) as the status message. For exceptions with an empty string representation (such as ValueError(), TimeoutError(), or custom exceptions without a message), the observation level was marked as "ERROR" but statusMessage remained empty (""), making the root exception type invisible in traces.

This change:

  1. Updates _get_error_level_and_status_message to fall back to type(error).__name__ when str(error) is empty (str(error) or type(error).__name__), matching the existing fallback used for control flow exceptions.
  2. Adds unit test test_error_without_message_uses_exception_type_as_status_message in tests/unit/test_langchain.py.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

List the main commands you ran:

pytest tests/unit/test_langchain.py
ruff check langfuse/langchain/CallbackHandler.py tests/unit/test_langchain.py
ruff format --check langfuse/langchain/CallbackHandler.py tests/unit/test_langchain.py

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

Ordinary exceptions with empty messages now use their class name as the status message.

  • LangChain traces name ordinary errors that have no message.

Reviews (1) · Last reviewed commit: "fix(langchain): fallback to exception cl..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

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.

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(python-sdk): LangChain callback records empty statusMessage for exceptions without a message

1 participant