Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.