Identify the lifecycle events that a LangChain `BaseCallbackHandler` natively exposes (select all that apply)
LangChain's BaseCallbackHandler exposes start/end/error events for LLM calls, chains, tools, and retrievers, plus agent action/finish, and nothing about GPU or auth.
Imagine a relay race coach who can only stopwatch the runners on her own team. She can clock when each runner starts a leg, when they finish, and whether they dropped the baton. She cannot clock the scoreboard wiring or the parking attendants because those are not her runners. LangChain's coach watches its own runners, model calls, chains, tools, retrievers, and tells you when each one started, ended, or tripped. Anything happening outside her team, like graphics-card timings or login screens, lives on a different scoreboard entirely.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 minutes: the four event categories, the agent events, the scope boundary, and the tracing-vendor wiring pattern.
from langchain_core.callbacks import BaseCallbackHandler
class MyTracer(BaseCallbackHandler):
def on_llm_start(self, serialized, prompts, *, run_id, parent_run_id=None, **kw):
print(f'LLM start: {run_id} parent={parent_run_id}')
def on_llm_end(self, response, *, run_id, **kw):
print(f'LLM end: {run_id} usage={response.llm_output}')
def on_tool_start(self, serialized, input_str, *, run_id, **kw):
print(f'Tool start: {serialized["name"]} run={run_id}')
def on_tool_error(self, error, *, run_id, **kw):
print(f'Tool error: {run_id} err={error}')Real products, models, and research that use this idea.
- Langfuse's LangChain integration registers a BaseCallbackHandler subclass and re-emits each event as an OpenTelemetry span.
- LangSmith's tracing client is a callback handler under the hood; nothing magic happens that you cannot replicate.
- Arize Phoenix and Helicone both wire in through the same callback surface; vendor switching is a callback registration change.
- OpenTelemetry's GenAI semantic conventions are designed to map cleanly onto the LangChain callback event names.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you implement a redaction layer that strips PII from prompts before they hit a tracing backend?
QWhat is the right way to propagate a parent OpenTelemetry trace context into LangChain callbacks?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming the callback surface includes provider-side details like token by token GPU timings, then writing custom handlers for events that never fire.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.