DeepchecksCallbackHandler
class DeepchecksCallbackHandler(BaseCallbackHandler)LangChain callback handler that streams chain, LLM, and tool events to the Deepchecks LLM platform.
Attach this handler to a LangChain runnable to automatically capture each step
of an interaction (prompts, responses, tool invocations, errors) and log it as
a Deepchecks interaction under the configured application/version.
Attributes
| Attribute | Description |
|---|---|
information_retrieval | Documents or context passages retrieved during the current interaction. |
input | The input prompt captured at the start of the current interaction. |
output | The model output captured at the end of the current interaction. |
started_at | UTC timestamp marking when the current interaction began. |
steps | Intermediate steps recorded during the current interaction, one per LangChain run. |
user_interaction_id | The user-supplied identifier for the current interaction, as a string. |
Methods
| Method | Description |
|---|---|
on_chain_end | Run when chain ends running. |
on_chain_start | Run when chain starts running. |
on_chat_model_start | Run when ChatModel starts running. |
on_llm_end | Run when LLM ends running. |
on_llm_error | Run when LLM errors. |
on_llm_start | Run when LLM starts running. |
on_retriever_end | Run when Retriever ends running. |
on_retriever_error | Run when Retriever errors. |
on_retriever_start | Run when Retriever starts running. |
information_retrieval
@property
def information_retrieval() -> list[str]Documents or context passages retrieved during the current interaction.
Returns
input
@property
def input() -> strThe input prompt captured at the start of the current interaction.
Returns
output
@property
def output() -> strThe model output captured at the end of the current interaction.
Returns
started_at
@property
def started_at() -> Union[datetime, None]UTC timestamp marking when the current interaction began.
Returns
- datetime | None
steps
@property
def steps() -> List[Step]Intermediate steps recorded during the current interaction, one per LangChain run.
Returns
user_interaction_id
@property
def user_interaction_id() -> Union[str, None]The user-supplied identifier for the current interaction, as a string.
Returns
- str | None
on_chain_end
def on_chain_end(outputs: Dict[str, Any], **kwargs: Any) -> AnyRun when chain ends running.
Parameters
Returns
on_chain_start
def on_chain_start(serialized: Dict[str, Any],
inputs: Dict[str, Any],
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
tags: Optional[List[str]] = None,
metadata: Optional[Dict[str, Any]] = None,
**kwargs: Any) -> NoneRun when chain starts running.
Parameters
- serialized (Dict[str, Any])
- inputs (Dict[str, Any])
- run_id (UUID)
- parent_run_id (UUID | None, default=None)
- tags (List[str] | None, default=None)
- metadata (Dict[str, Any] | None, default=None)
**kwargs(Any)
Returns
on_chat_model_start
def on_chat_model_start(serialized: Dict[str, Any],
messages: List[List[BaseMessage]],
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
tags: Optional[List[str]] = None,
metadata: Optional[Dict[str, Any]] = None,
**kwargs: Any) -> AnyRun when ChatModel starts running.
Parameters
- serialized (Dict[str, Any])
- messages (List[List[BaseMessage]])
- run_id (UUID)
- parent_run_id (UUID | None, default=None)
- tags (List[str] | None, default=None)
- metadata (Dict[str, Any] | None, default=None)
**kwargs(Any)
Returns
on_llm_end
def on_llm_end(response: LLMResult, **kwargs: Any) -> AnyRun when LLM ends running.
Parameters
Returns
on_llm_error
def on_llm_error(error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> AnyRun when LLM errors.
Parameters
- error (Exception | KeyboardInterrupt)
**kwargs(Any)
Returns
on_llm_start
def on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) -> AnyRun when LLM starts running.
Parameters
Returns
on_retriever_end
def on_retriever_end(documents: Sequence[Document],
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
**kwargs: Any) -> AnyRun when Retriever ends running.
Parameters
- documents (Sequence[Document])
- run_id (UUID)
- parent_run_id (UUID | None, default=None)
**kwargs(Any)
Returns
on_retriever_error
def on_retriever_error(error: BaseException,
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
**kwargs: Any) -> AnyRun when Retriever errors.
Parameters
- error (BaseException)
- run_id (UUID)
- parent_run_id (UUID | None, default=None)
**kwargs(Any)
Returns
on_retriever_start
def on_retriever_start(serialized: Dict[str, Any],
query: str,
*,
run_id: UUID,
parent_run_id: Optional[UUID] = None,
tags: Optional[List[str]] = None,
metadata: Optional[Dict[str, Any]] = None,
**kwargs: Any) -> AnyRun when Retriever starts running.
Parameters
- serialized (Dict[str, Any])
- query (str)
- run_id (UUID)
- parent_run_id (UUID | None, default=None)
- tags (List[str] | None, default=None)
- metadata (Dict[str, Any] | None, default=None)
**kwargs(Any)