> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# FiddlerCallbackHandler

> LangChain callback handler that creates Fiddler OTel spans for every chain, LLM, tool, agent, and retriever lifecycle event.

Can be used directly by passing it in the `callbacks` array of a
LangChain/LangGraph invocation, or automatically injected via
LangGraphInstrumentor.

## Properties

### `name: string`

**Value:** `'FiddlerCallbackHandler'`

## Methods

### `constructor(client: FiddlerClient)`

**client** `FiddlerClient` *required*

An initialized FiddlerClient used to create spans.

### `handleAgentAction(action: AgentAction, runId: string)`

Called when an agent decides to invoke a tool.

Updates the existing agent span with the chosen tool name and input.

**action** `AgentAction` *required*

The agent action containing tool name and input.

**runId** `string` *required*

Run identifier to look up the span.

### `handleAgentEnd(action: AgentFinish, runId: string)`

Called when an agent produces its final answer.

Updates the existing agent span with the return values.

**action** `AgentFinish` *required*

The agent finish containing return values.

**runId** `string` *required*

Run identifier to look up the span.

### `handleChainEnd(outputs: ChainValues, runId: string)`

Called when a chain/graph node completes successfully.

**outputs** `ChainValues` *required*

Output values produced by the chain.

**runId** `string` *required*

Run identifier to look up the span.

### `handleChainError(error: Error, runId: string)`

Called when a chain/graph node throws an error.

**error** `Error` *required*

The error that occurred.

**runId** `string` *required*

Run identifier to look up the span.

### `handleChainStart(serialized: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>)`

Called when a LangChain chain/graph node begins execution.

Creates a chain or `langgraph_node` span with input and agent
identity attributes.

**serialized** `Serialized` *required*

Serialized chain/runnable metadata.

**inputs** `ChainValues` *required*

Input values passed to the chain.

**runId** `string` *required*

Unique run identifier.

**parentRunId** `string`

Parent run ID for nesting.

**tags** `string[]`

LangChain tags (used for LangGraph node detection).

**metadata** `Record\<string, unknown\>`

LangChain metadata (agent name, node name, etc.).

### `handleChatModelStart(serialized: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, _tags?: string[], _metadata?: Record<string, unknown>, runName?: string)`

Called when a chat model call begins (e.g. ChatOpenAI, ChatAnthropic).

Creates an LLM span with model name, provider, system/user messages,
and optional LLM context.

**serialized** `Serialized` *required*

Serialized chat model metadata.

**messages** `BaseMessage[][]` *required*

2D array of chat messages (outer = batches).

**runId** `string` *required*

Unique run identifier.

**parentRunId** `string`

Parent run ID for nesting.

**extraParams** `Record\<string, unknown\>`

Additional invocation parameters.

**\_tags** `string[]`

LangChain tags.

**\_metadata** `Record\<string, unknown\>`

LangChain metadata.

**runName** `string`

Optional explicit run name.

### `handleLLMEnd(output: LLMResult, runId: string)`

Called when an LLM call completes.

Sets completion text and token usage attributes on the span.

**output** `LLMResult` *required*

The LLMResult containing generations and usage.

**runId** `string` *required*

Run identifier to look up the span.

### `handleLLMError(error: Error, runId: string)`

Called when an LLM call throws an error.

**error** `Error` *required*

The error that occurred.

**runId** `string` *required*

Run identifier to look up the span.

### `handleLLMStart(serialized: Serialized, prompts: string[], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, _tags?: string[], _metadata?: Record<string, unknown>, runName?: string)`

Called when a non-chat LLM call begins (e.g. completion models).

Creates an LLM span with model name, provider, and prompt attributes.

**serialized** `Serialized` *required*

Serialized LLM metadata.

**prompts** `string[]` *required*

Array of prompt strings.

**runId** `string` *required*

Unique run identifier.

**parentRunId** `string`

Parent run ID for nesting.

**\_extraParams** `Record\<string, unknown\>`

Additional invocation parameters.

**\_tags** `string[]`

LangChain tags.

**\_metadata** `Record\<string, unknown\>`

LangChain metadata.

**runName** `string`

Optional explicit run name.

### `handleRetrieverEnd(documents: { metadata?: unknown; pageContent?: string }[], runId: string)`

Called when a retriever returns documents.

Sets the concatenated page content as the tool output.

**documents** `\{ metadata?: unknown; pageContent?: string \}[]` *required*

Array of retrieved documents with `pageContent`.

**runId** `string` *required*

Run identifier to look up the span.

### `handleRetrieverError(error: Error, runId: string)`

Called when a retriever throws an error.

**error** `Error` *required*

The error that occurred.

**runId** `string` *required*

Run identifier to look up the span.

### `handleRetrieverStart(serialized: Serialized, query: string, runId: string, parentRunId?: string)`

Called when a retriever begins fetching documents.

Creates a tool-type span with the retriever name and query.

**serialized** `Serialized` *required*

Serialized retriever metadata.

**query** `string` *required*

The search query string.

**runId** `string` *required*

Unique run identifier.

**parentRunId** `string`

Parent run ID for nesting.

### `handleToolEnd(output: string, runId: string)`

Called when a tool invocation completes successfully.

Extracts the output content — handles both plain strings and
LangGraph `ToolMessage` objects that carry a `.content` field.

**output** `string` *required*

Tool output (string or ToolMessage-like object).

**runId** `string` *required*

Run identifier to look up the span.

### `handleToolError(error: Error, runId: string)`

Called when a tool invocation throws an error.

**error** `Error` *required*

The error that occurred.

**runId** `string` *required*

Run identifier to look up the span.

### `handleToolStart(serialized: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[], _metadata?: Record<string, unknown>, runName?: string)`

Called when a tool invocation begins.

Creates a tool span with the tool name and input.

**serialized** `Serialized` *required*

Serialized tool metadata.

**input** `string` *required*

The input string or structured input for the tool.

**runId** `string` *required*

Unique run identifier.

**parentRunId** `string`

Parent run ID for nesting.

**\_tags** `string[]`

LangChain tags.

**\_metadata** `Record\<string, unknown\>`

LangChain metadata.

**runName** `string`

Optional explicit run name.
