Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include stacktrace context in messages for caught exceptions from LLM functions & function callbacks. #241

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

montebrown
Copy link
Contributor

@montebrown montebrown commented Jan 26, 2025

Hi! In upgrading some code to 0.3.0 I had a few exceptions to track down and found the lack of context in the caught error messages slowed things down.

This change adds context to the error messages logged and kept in the chain for LLM functions and function callbacks. I took an initial stab at the places this seems most valuable while avoiding putting full stack traces in the chain.

The details:

  • caught exceptions were logging their type and message, however, without a stack trace or location for the exception debugging was required to locate some issues.
  • added format_exception/3 to LangChain.LangChainError to format exceptions with context from the stacktrace. The third argument is the format - :short only includes the location and the default gives a full stack trace at the end of the message.
  • I updated the most obvious places where a lack of context could slow down fixing issues, however there are other rescue blocks where this may be useful.

…ctions and function callbacks.

 - caught exceptions were logging their type and message, however, without a stack trace or location for the exception debugging may be required to locate some issues. 
 - added format_exception/3 to LangChain.LangChainError to format exceptions with context from the stacktrace. The third argument is the format - :short only includes the location and the default gives a full stack trace at the end of the message.
 - I updated the most obvious places where a lack of context could slow down fixing issues, however there are other rescue blocks where this may be useful.
@brainlid
Copy link
Owner

Very nice! I love this. Thanks! I appreciate the updated test coverage too.
❤️💛💙💜

@brainlid brainlid merged commit b349f18 into brainlid:main Jan 30, 2025
1 check passed
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.

2 participants