# MlflowCallbackHandler

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler)

Callback Handler that logs metrics and artifacts to mlflow server.

## Signature

```python
MlflowCallbackHandler(
    self,
    name: Optional[str] = 'langchainrun-%',
    experiment: Optional[str] = 'langchain',
    tags: Optional[Dict] = None,
    tracking_uri: Optional[str] = None,
    run_id: Optional[str] = None,
    artifacts_dir: str = '',
)
```

## Description

This handler will utilize the associated callback method called and formats
the input of each callback function with metadata regarding the state of LLM run,
and adds the response to the list of records for both the {method}_records and
action. It then logs the response to mlflow server.

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | `str` | No | Name of the run. (default: `'langchainrun-%'`) |
| `experiment` | `str` | No | Name of the experiment. (default: `'langchain'`) |
| `tags` | `dict` | No | Tags to be attached for the run. (default: `None`) |
| `tracking_uri` | `str` | No | MLflow tracking server uri. (default: `None`) |

## Extends

- `BaseMetadataCallbackHandler`
- `BaseCallbackHandler`

## Constructors

```python
__init__(
    self,
    name: Optional[str] = 'langchainrun-%',
    experiment: Optional[str] = 'langchain',
    tags: Optional[Dict] = None,
    tracking_uri: Optional[str] = None,
    run_id: Optional[str] = None,
    artifacts_dir: str = '',
) -> None
```

| Name | Type |
|------|------|
| `name` | `Optional[str]` |
| `experiment` | `Optional[str]` |
| `tags` | `Optional[Dict]` |
| `tracking_uri` | `Optional[str]` |
| `run_id` | `Optional[str]` |
| `artifacts_dir` | `str` |


## Properties

- `name`
- `experiment`
- `tags`
- `tracking_uri`
- `run_id`
- `artifacts_dir`
- `temp_dir`
- `mlflg`
- `action_records`
- `nlp`
- `textstat`
- `metrics`
- `records`

## Methods

- [`on_llm_start()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_llm_start)
- [`on_llm_new_token()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_llm_new_token)
- [`on_llm_end()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_llm_end)
- [`on_llm_error()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_llm_error)
- [`on_chain_start()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_chain_start)
- [`on_chain_end()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_chain_end)
- [`on_chain_error()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_chain_error)
- [`on_tool_start()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_tool_start)
- [`on_tool_end()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_tool_end)
- [`on_tool_error()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_tool_error)
- [`on_text()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_text)
- [`on_agent_finish()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_agent_finish)
- [`on_agent_action()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_agent_action)
- [`on_retriever_start()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_retriever_start)
- [`on_retriever_end()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_retriever_end)
- [`on_retriever_error()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/on_retriever_error)
- [`flush_tracker()`](https://reference.langchain.com/python/langchain-community/callbacks/mlflow_callback/MlflowCallbackHandler/flush_tracker)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/d5ea8358933260ad48dd31f7f8076555c7b4885a/libs/community/langchain_community/callbacks/mlflow_callback.py#L249)