Debugging
Tracing and history.
When a graph gives a wrong answer, you need to see what happened inside. Three tools help. Streaming updates, to see each step. State history, to see the state at every checkpoint. And tracing, for everything at once.

- Wrong answer?
- See inside
- Three tools
Finding where it went wrong
Here, a customer's title was misspelled, so price fails with a key error. We catch it, then use get state to see exactly where the run stopped, and what the state held. Run it. Next shows the run stopped at price, and the values show the misspelled title that caused it.
from order_graph import graph
config = {"configurable": {"thread_id": "bug-1"}}
try:
graph.invoke({"title": "dnue", "quantity": 1}, config)
except KeyError as error:
print("failed with KeyError:", error)
snapshot = graph.get_state(config)
print("stopped before:", snapshot.next)
print("state was:", snapshot.values)failed with KeyError: 'Dnue'
stopped before: ('price',)
state was: {'title': 'Dnue', 'quantity': 1}Also uses order_graph.py
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END
PRICES = {"Dune": 9.99, "Circe": 10.99}
class Order(TypedDict):
title: str
quantity: int
total: float
receipt: str
def clean(s):
return {"title": s["title"].strip().title()}
def price(s):
return {"total": round(PRICES[s["title"]] * s["quantity"], 2)}
def receipt(s):
return {"receipt": f"{s['quantity']} x {s['title']} = £{s['total']}"}
b = StateGraph(Order)
b.add_sequence([clean, price, receipt])
b.add_edge(START, "clean"); b.add_edge("receipt", END)
graph = b.compile(checkpointer=InMemorySaver())Debugging toolkit
Get state shows where a run stopped. State history shows every step before it. Streaming shows steps live. And LangSmith tracing, turned on with environment variables, shows every node, prompt, tool call, and timing, in one view.
| key | value |
|---|---|
| get_state | where it stopped |
| History | every step |
| Streaming | live view |
| LangSmith | everything at once |
Summary
Use get state, state history, streaming, and tracing to see inside a graph, and find bugs fast. Next, saving checkpoints to disk.
Key takeaways- get_state after errors
- State history
- LangSmith tracing