CallbackManagerForLLMRun Class — langchain Architecture
Architecture documentation for the CallbackManagerForLLMRun class in manager.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8["CallbackManagerForLLMRun"] 9ee9bc25_3f67_6972_bad7_11cbc05986ad["RunManager"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|extends| 9ee9bc25_3f67_6972_bad7_11cbc05986ad ec453097_9dd7_3edc_a70f_a6b65b8f3e63["LLMManagerMixin"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|extends| ec453097_9dd7_3edc_a70f_a6b65b8f3e63 35cf5db6_bcb1_b854_6ebb_5e0368e51b58["manager.py"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|defined in| 35cf5db6_bcb1_b854_6ebb_5e0368e51b58 a390fcf8_5a1b_1fd6_01c0_9ee0dffae9b3["on_llm_new_token()"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|method| a390fcf8_5a1b_1fd6_01c0_9ee0dffae9b3 9460d0b1_4473_4b37_5ed1_65dcf90a8667["on_llm_end()"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|method| 9460d0b1_4473_4b37_5ed1_65dcf90a8667 5a30ab3c_c6bf_529b_8839_60cb2a22b4d4["on_llm_error()"] 4a47bffe_726e_6355_d3b1_4c4ddbbd9cc8 -->|method| 5a30ab3c_c6bf_529b_8839_60cb2a22b4d4
Relationship Graph
Source Code
libs/core/langchain_core/callbacks/manager.py lines 672–750
class CallbackManagerForLLMRun(RunManager, LLMManagerMixin):
"""Callback manager for LLM run."""
def on_llm_new_token(
self,
token: str,
*,
chunk: GenerationChunk | ChatGenerationChunk | None = None,
**kwargs: Any,
) -> None:
"""Run when LLM generates a new token.
Args:
token: The new token.
chunk: The chunk.
**kwargs: Additional keyword arguments.
"""
if not self.handlers:
return
handle_event(
self.handlers,
"on_llm_new_token",
"ignore_llm",
token=token,
run_id=self.run_id,
parent_run_id=self.parent_run_id,
tags=self.tags,
chunk=chunk,
**kwargs,
)
def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
"""Run when LLM ends running.
Args:
response: The LLM result.
**kwargs: Additional keyword arguments.
"""
if not self.handlers:
return
handle_event(
self.handlers,
"on_llm_end",
"ignore_llm",
response,
run_id=self.run_id,
parent_run_id=self.parent_run_id,
tags=self.tags,
**kwargs,
)
def on_llm_error(
self,
error: BaseException,
**kwargs: Any,
) -> None:
"""Run when LLM errors.
Args:
error: The error.
**kwargs: Additional keyword arguments.
- response (LLMResult): The response which was generated before
the error occurred.
"""
if not self.handlers:
return
handle_event(
self.handlers,
"on_llm_error",
"ignore_llm",
error,
run_id=self.run_id,
parent_run_id=self.parent_run_id,
tags=self.tags,
**kwargs,
)
Extends
Source
Frequently Asked Questions
What is the CallbackManagerForLLMRun class?
CallbackManagerForLLMRun is a class in the langchain codebase, defined in libs/core/langchain_core/callbacks/manager.py.
Where is CallbackManagerForLLMRun defined?
CallbackManagerForLLMRun is defined in libs/core/langchain_core/callbacks/manager.py at line 672.
What does CallbackManagerForLLMRun extend?
CallbackManagerForLLMRun extends RunManager, LLMManagerMixin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free