Introduction to LangSmith observability showing how execution traces in LangGraph and LangChain record prompts, tool calls, state changes, errors, and performance for debugging
When you deploy AI agents in production, observability becomes critical. Without visibility into internal execution—what nodes ran, which prompts were used, what inputs were processed, and how state changed—debugging is nearly impossible. LangSmith provides observability tools built specifically for large language model (LLM) applications to make these internals visible and actionable.LangSmith is an observability platform created by the LangChain team for monitoring, debugging, and improving systems built with frameworks like LangChain and LangGraph. Its core concept is the execution trace: every run of your application is recorded in full. Traces capture model inputs and outputs, prompt versions, tool calls, errors, latency, and workflow state changes so you can inspect exactly how an agent behaved.
You can trace each step of a workflow to find where errors occurred, examine which prompts and tools contributed to a result, and analyze execution latency. Practically, LangSmith acts like mission control for LLM applications, giving developers complete visibility into agent internals.Every time an agent runs, multiple components interact: models receive inputs, prompts are constructed and versioned, tools may be called, graph state can change, and the model generates outputs. Complex agent systems may perform thousands of decisions and interactions in a single run. Without observability, this all looks like a black box—you only see the final response.
LangSmith records an execution trace whenever your agent runs. A trace is a detailed timeline describing:
Model inputs and outputs
Tool calls and external API interactions
Node execution sequence and state transitions
Latency measurements and timing per step
Errors and full tracebacks
Prompt versions used during the run
Inspecting traces lets you see the exact prompt that was sent, which tool was invoked, how state evolved, and where failures or slowdowns occurred—turning guesswork into diagnosis.Robby used to just deliver packages. Now his clipboard tracks every step — which doors he knocked on, what he said, and where he had issues. LangSmith is that clipboard, but for your graph.LangGraph integrates natively with LangSmith, so enabling tracing usually requires only a few lines of configuration. Once enabled, detailed traces are automatically sent to LangSmith for every LangGraph run.
Traces include per-step details (inputs, outputs, tool calls, node transitions, latency) and can be enriched with custom metadata such as session IDs, user IDs, or experiment tags. This metadata helps correlate user activity and configuration with system behavior—critical for robust debugging and production monitoring.Getting started with LangSmith tracing is simple. Add the tracing initialization early in your application:
from langgraph.tracing.langsmith import enable_tracing# Enable LangSmith tracing for all LangGraph runsenable_tracing()
When tracing is enabled, LangGraph opens a trace session for each run and captures events like node execution, model calls, tool invocations, state updates, and timings. All captured data is sent to LangSmith and stored as an execution trace for later inspection.
Initialize tracing before your graph executes. Tracing begins only after enable_tracing() is called, so place it at the top of your script, app startup, or notebook cell that runs prior to graph execution.
LangGraph’s tracing is non-invasive: you do not need to modify node functions or change workflow logic. The framework records execution details without altering runtime behavior.
What LangSmith records (at a glance)
Layer
What is captured
Why it matters
Execution path
Sequence of nodes executed in the graph
See exactly which branches ran and why
Model/Chain calls
Model inputs, outputs, prompt versions
Reproduce responses and audit prompts
Tool usage
Tool names, arguments, results, API calls
Debug external integrations and failures
Agent decisions
Intermediate reasoning steps
Understand decision points and logic flow
Performance
Latency and per-step timings
Identify bottlenecks and optimize performance
Errors
Full tracebacks and failure context
Faster root-cause analysis
In local testing, prints and logs can sometimes be enough. But production workflows typically have branching logic, external calls, stateful memory, and unpredictable user inputs. Two runs with similar inputs may take different execution paths; traces let you compare runs side-by-side.
Key investigation tools in LangSmith
Feature
How it helps
Visual node traces
See the path the graph took visually and quickly identify branches
Step-by-step breakdowns
Inspect inputs/outputs for each node and tool call
Prompt version history
Audit which prompt template or version was used for a given run
Session replay
Replay previous runs to understand behavior over time
Detailed error context
View full tracebacks and surrounding state to accelerate fixes
Best practices for production observability
Enable tracing for development and staging to detect regressions early.
Use session tags (user IDs, agent names, experiment IDs) to filter and group traces.
Attach custom metadata (prompt version, model version, memory size) to correlate configuration with behavior.
Review traces for subtle issues (unexpected outputs, memory mis-recall), not just explicit errors.
Configure dashboards and alerts to surface critical signals like latency spikes or recurring failures.
LangSmith gives you a visual trace of LangGraph execution: which nodes ran, what each step did, and how long each took. If a run fails, inspect the full error context; if it’s slow, identify the slow step. This shifts debugging from speculative to diagnostic.
Troubleshooting and validation use cases
Answering tough questions: When two similar inputs yield different outputs, traces reveal which nodes executed, the exact prompts sent, and any memory or state accessed.
Validating changes: After modifying prompts, reducers, or memory logic, use traces to confirm the new behavior before releasing to users.
Performance tuning: Identify slow tools or model calls and prioritize optimizations based on per-step timings.
Operationalizing observability
Enrich traces with metadata (user IDs, input types, version tags) for easier filtering and correlation.
Add monitoring, dashboards, and alerts to detect important signals automatically (latency spikes, frequent retries, long execution chains).
After updates (prompts, reducers, memory), inspect sample traces across key flows to ensure expected behavior.
LangGraph enables powerful, stateful agent workflows—and that power brings complexity. As graphs grow, tracing becomes essential to understand actual execution, debug failures, and validate changes. Observability tools like LangSmith help teams build AI systems that are more robust, explainable, and maintainable.
Be mindful of sensitive data. Traces can capture user inputs and API responses—sanitize or redact personally identifiable information (PII) and secrets before storing or sharing traces.
For engineers building production agents, LangSmith becomes an essential part of the monitoring and debugging toolkit—turning opaque agent runs into inspectable, repeatable traces.Links and references