Skip to Content
Sarek AI AccountabilitySDK ReferenceTypeScriptLangChain

LangChain API Reference (TypeScript)

Method signatures, option types and extended log fields for the LangChain and LangGraph callback path. For a guide-level introduction, see LangChain.

langchain()

Returns a LangChain BaseCallbackHandler that you pass into callbacks. Async because LangChain is imported on demand. Create one callback per request so each request gets its own trace.

Signature

langchain(options?: LangChainCallbackOptions): Promise<BaseCallbackHandler>

Parameters

NameTypeDefaultDescription
options.rolestring'unspecified'Overrides the role set on AiLogger.init() for this callback.
options.traceIdstringautoCustom trace id. Defaults to the root run’s runId.
options.onError(err: Error, context: CallbackErrorContext) => voidCalled when an internal handler error occurs. If omitted, the error and its entry are dropped silently.

Returns

Promise<BaseCallbackHandler>.

Example

import { AiLogger } from '@sarek/ai-accountability' const sarek = await AiLogger.init({ name: 'loan-desk' }) const callback = await sarek.langchain({ role: 'credit-assessor', traceId: 'request-2026-06-16-4821', onError: (err, context) => { appLogger.error('sarek callback error', { handler: context.handler, runId: context.runId, err }) } })

langgraph()

Alias for langchain(). Use it for LangGraph apps; the callback behaves identically.

Signature

langgraph(options?: LangChainCallbackOptions): Promise<BaseCallbackHandler>

Event types

The callback logs five event types. The discriminator is eventType:

EventStart handlerInput hashOutput hash
llmchat model or legacy LLM startthe prompt messages or stringsthe generated text
tooltool startthe tool inputthe tool output
retrieverretriever startthe querydocument metadata only, never content
chainchain startthe chain inputsthe chain outputs
errorLLM, tool or chain errorreused from the matching startempty

Extended LogEntry fields

On top of the standard LogEntry fields, the callback path populates these:

FieldSourceNotes
eventTypethe handler that firedllm, tool, retriever, chain or error
outcomethe handler that firedsuccess, or error on a failed call
traceIdthe root run’s runIdequals LangSmith’s trace_id; ties one request together
runIdthe callback’s run id for this eventunique per event
parentRunIdthe callback’s parent run idnull on the root; reconstructs the call tree
chainNamethe serialized chain idchain events
toolNamethe tool nametool events
toolCallIdthe model’s tool-call idlinks a tool event to the call that requested it
errorClassthe exception class nameerror events
errorHashSHA3-256 of the error messagethe raw message is never stored
modelParamsconfigured from the invocation params, actual from the resultllm events only; see below
thread_idmetadata.thread_idLangGraph; null for plain LangChain
langgraph_nodemetadata.langgraph_nodeLangGraph; null otherwise
langgraph_stepmetadata.langgraph_stepLangGraph; null otherwise
checkpoint_nsmetadata.checkpoint_nsLangGraph; null otherwise
tags, metadatapassed through from the callbackcarry deployer context, end-user id, jurisdiction

modelParams: configured against actual

On llm events, modelParams separates what you asked for from what the provider reported:

  • configured holds temperature, maxTokens and topP, read from the invocation parameters LangChain builds for the call. These are the same values LangSmith logs.
  • actual holds the provider’s own output block, framed as what the provider actually reported. Many providers leave most of it empty, which is expected.

Retriever output is metadata only

For retriever events the output hash is computed over the id and source of each retrieved document, never the document content. The page content never leaves the SDK. If you need the content for retention, keep it yourself.

Fields that differ on this path

A few standard LogEntry fields do not carry their usual meaning when the entry comes from a callback:

FieldOn the callback path
predictionIdempty; LangChain does not surface a provider response id here
citationsnot populated; this is a Perplexity-only field on the direct path
statusCodealways 200. Use outcome for success or failure, not the status code
environmentprocess.env.NODE_ENV
Last updated on