> ## 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

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`

## Methods

### `constructor(client: FiddlerClient)`

<ParamField path="client" type="FiddlerClient" required={true}>
  An initialized FiddlerClient used to create spans.
</ParamField>

### `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.

<ParamField path="action" type="AgentAction" required={true}>
  The agent action containing tool name and input.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when an agent produces its final answer.

Updates the existing agent span with the return values.

<ParamField path="action" type="AgentFinish" required={true}>
  The agent finish containing return values.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when a chain/graph node completes successfully.

<ParamField path="outputs" type="ChainValues" required={true}>
  Output values produced by the chain.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when a chain/graph node throws an error.

<ParamField path="error" type="Error" required={true}>
  The error that occurred.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

### `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.

<ParamField path="serialized" type="Serialized" required={true}>
  Serialized chain/runnable metadata.
</ParamField>

<ParamField path="inputs" type="ChainValues" required={true}>
  Input values passed to the chain.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Unique run identifier.
</ParamField>

<ParamField path="parentRunId" type="string" required={false}>
  Parent run ID for nesting.
</ParamField>

<ParamField path="tags" type="string[]" required={false}>
  LangChain tags (used for LangGraph node detection).
</ParamField>

<ParamField path="metadata" type="Record<string, unknown>" required={false}>
  LangChain metadata (agent name, node name, etc.).
</ParamField>

### `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.

<ParamField path="serialized" type="Serialized" required={true}>
  Serialized chat model metadata.
</ParamField>

<ParamField path="messages" type="BaseMessage[][]" required={true}>
  2D array of chat messages (outer = batches).
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Unique run identifier.
</ParamField>

<ParamField path="parentRunId" type="string" required={false}>
  Parent run ID for nesting.
</ParamField>

<ParamField path="extraParams" type="Record<string, unknown>" required={false}>
  Additional invocation parameters.
</ParamField>

<ParamField path="_tags" type="string[]" required={false} />

<ParamField path="_metadata" type="Record<string, unknown>" required={false} />

<ParamField path="runName" type="string" required={false}>
  Optional explicit run name.
</ParamField>

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

Called when an LLM call completes.

Sets completion text and token usage attributes on the span.

<ParamField path="output" type="LLMResult" required={true}>
  The LLMResult containing generations and usage.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when an LLM call throws an error.

<ParamField path="error" type="Error" required={true}>
  The error that occurred.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

### `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.

<ParamField path="serialized" type="Serialized" required={true}>
  Serialized LLM metadata.
</ParamField>

<ParamField path="prompts" type="string[]" required={true}>
  Array of prompt strings.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Unique run identifier.
</ParamField>

<ParamField path="parentRunId" type="string" required={false}>
  Parent run ID for nesting.
</ParamField>

<ParamField path="_extraParams" type="Record<string, unknown>" required={false} />

<ParamField path="_tags" type="string[]" required={false} />

<ParamField path="_metadata" type="Record<string, unknown>" required={false} />

<ParamField path="runName" type="string" required={false}>
  Optional explicit run name.
</ParamField>

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

Called when a retriever returns documents.

Sets the concatenated page content as the tool output.

<ParamField path="documents" type="{ metadata?: unknown; pageContent?: string }[]" required={true}>
  Array of retrieved documents with `pageContent`.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when a retriever throws an error.

<ParamField path="error" type="Error" required={true}>
  The error that occurred.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

### `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.

<ParamField path="serialized" type="Serialized" required={true}>
  Serialized retriever metadata.
</ParamField>

<ParamField path="query" type="string" required={true}>
  The search query string.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Unique run identifier.
</ParamField>

<ParamField path="parentRunId" type="string" required={false}>
  Parent run ID for nesting.
</ParamField>

### `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.

<ParamField path="output" type="string" required={true}>
  Tool output (string or ToolMessage-like object).
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

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

Called when a tool invocation throws an error.

<ParamField path="error" type="Error" required={true}>
  The error that occurred.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Run identifier to look up the span.
</ParamField>

### `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.

<ParamField path="serialized" type="Serialized" required={true}>
  Serialized tool metadata.
</ParamField>

<ParamField path="input" type="string" required={true}>
  The input string or structured input for the tool.
</ParamField>

<ParamField path="runId" type="string" required={true}>
  Unique run identifier.
</ParamField>

<ParamField path="parentRunId" type="string" required={false}>
  Parent run ID for nesting.
</ParamField>

<ParamField path="_tags" type="string[]" required={false} />

<ParamField path="_metadata" type="Record<string, unknown>" required={false} />

<ParamField path="runName" type="string" required={false}>
  Optional explicit run name.
</ParamField>
