-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Checked other resources
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
from langchain_core.callbacks.manager import handle_event
from unittest.mock import Mock
handler = Mock()
handler.on_chat_model_start = Mock(side_effect=NotImplementedError)
handlers = [handler]
event_name = "on_chat_model_start"
ignore_condition_name = None
handle_event(handlers, event_name, ignore_condition_name)
Error Message and Stack Trace (if applicable)
Traceback (most recent call last):
...
File ".../langchain_core/callbacks/manager.py", line 276, in handle_event
message_strings = [get_buffer_string(m) for m in args[1]]
IndexError: tuple index out of range
Description
The following code works fine and logs: Error in Mock.on_chat_model_start callback: KeyError()
from langchain_core.callbacks.manager import handle_event
from unittest.mock import Mock
handler = Mock()
handler.on_chat_model_start = Mock(side_effect=KeyError)
handlers = [handler]
event_name = "on_chat_model_start"
ignore_condition_name = None
handle_event(handlers, event_name, ignore_condition_name)
However, when I change the handler's raised exception to NotImplementedError
, it raises IndexError
and NotImplementedError
is hidden.
System Info
System Information
OS: Linux
OS Version: #148-Ubuntu SMP Fri Mar 14 19:05:48 UTC 2025
Python Version: 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0]
Package Information
langchain_core: 0.3.28
langchain: 0.3.13
langchain_community: 0.3.13
langsmith: 0.1.137
langchain_anthropic: 0.3.1
langchain_aws: 0.2.2
langchain_chroma: 0.2.0
langchain_experimental: 0.3.2
langchain_fireworks: 0.2.6
langchain_google_vertexai: 2.0.5
langchain_groq: 0.2.2
langchain_mistralai: 0.2.4
langchain_openai: 0.2.14
langchain_text_splitters: 0.3.4
langchain_together: 0.2.0
langchain_unstructured: 0.1.5
langgraph_sdk: 0.1.34
Optional packages not installed
langserve
Other Dependencies
aiohttp: 3.10.10
anthropic: 0.40.0
anthropic[vertexai]: Installed. No version info available.
async-timeout: 4.0.3
boto3: 1.35.42
chromadb: 0.5.15
dataclasses-json: 0.6.7
defusedxml: 0.7.1
fastapi: 0.115.3
fireworks-ai: 0.15.7
google-cloud-aiplatform: 1.70.0
google-cloud-storage: 2.18.2
groq: 0.11.0
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch: 1.33
numpy: 1.26.4
openai: 1.57.4
orjson: 3.10.16
packaging: 24.1
pydantic: 2.11.1
pydantic-settings: 2.6.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.40
tenacity: 9.0.0
tiktoken: 0.8.0
tokenizers: 0.21.0
typing-extensions: 4.13.0
unstructured-client: 0.25.9
unstructured[all-docs]: Installed. No version info available.