trace_as_chain_group#
- langchain_core.callbacks.manager.trace_as_chain_group(group_name: str, callback_manager: CallbackManager | None = None, *, inputs: Dict[str, Any] | None = None, project_name: str | None = None, example_id: str | UUID | None = None, run_id: UUID | None = None, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None) Generator[CallbackManagerForChainGroup, None, None] [source]#
Get a callback manager for a chain group in a context manager. Useful for grouping different calls together as a single run even if they arenβt composed in a single chain.
- Parameters:
group_name (str) β The name of the chain group.
callback_manager (CallbackManager, optional) β The callback manager to use. Defaults to None.
inputs (Dict[str, Any], optional) β The inputs to the chain group. Defaults to None.
project_name (str, optional) β The name of the project. Defaults to None.
example_id (str or UUID, optional) β The ID of the example. Defaults to None.
run_id (UUID, optional) β The ID of the run.
tags (List[str], optional) β The inheritable tags to apply to all runs. Defaults to None.
metadata (Dict[str, Any], optional) β The metadata to apply to all runs. Defaults to None.
- Return type:
Generator[CallbackManagerForChainGroup, None, None]
Note: must have LANGCHAIN_TRACING_V2 env var set to true to see the trace in LangSmith.
- Returns:
The callback manager for the chain group.
- Return type:
- Parameters:
group_name (str) β
callback_manager (CallbackManager | None) β
inputs (Dict[str, Any] | None) β
project_name (str | None) β
example_id (str | UUID | None) β
run_id (UUID | None) β
tags (List[str] | None) β
metadata (Dict[str, Any] | None) β
Example
llm_input = "Foo" with trace_as_chain_group("group_name", inputs={"input": llm_input}) as manager: # Use the callback manager for the chain group res = llm.invoke(llm_input, {"callbacks": manager}) manager.on_chain_end({"output": res})