Skip to main content

How to See What Each Node Returns in a LangGraph Graph in Python

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

graph.invoke() gives you only the final state, so when a result looks wrong, it doesn't tell you which node did what. graph.stream() with stream_mode="updates" prints what each node returned, one node at a time. This guide uses it on a two-node graph with LangGraph 1.2.25.

Syntax​

Syntax
for <update> in <graph>.stream(<input>, stream_mode="updates"):
print(<update>)
PartWhat it means
<graph>A compiled graph, the result of compile()
<input>The starting state: the same dictionary you'd pass to invoke()
stream_mode="updates"Asks for each node's update, as soon as the node has run
<update>One dictionary per node that ran, with the node's name as the key and what the node returned as the value

LangGraph's streaming guide says that updates "streams the updates to the state after each step of the graph", and it shows each one in the shape {"node_name": {"key": "value"}}.

The Example​

A graph with two nodes. clean takes a name typed with stray spaces and small letters, " ada lovelace ", and tidies it into Ada Lovelace. greet then builds a greeting from the tidy name. No AI model is involved, so no API key is needed.

Prerequisites​

  • uv. This guide uses uv 0.13.10 with Python 3.14.10.

Step 1: Create the Project​

In a terminal, in the folder where you keep your projects, create a project, move into it and add LangGraph:

Terminal
uv init --python 3.14 --no-package name-greeter
cd name-greeter
uv add langgraph
Output (shortened)
Initialized project `name-greeter` at `/Users/you/source/name-greeter`
Using CPython 3.14.10
Creating virtual environment at: .venv
Resolved 40 packages in 26ms
Installed 38 packages in 81ms
+ langgraph==1.2.25

The terminal after uv init, cd and uv add langgraph: the name-greeter project was initialized, uv used CPython 3.14.10, resolved 40 packages and installed 38, among them langgraph 1.2.25.

How to Install LangGraph in Python with uv explains these commands and the packages they install.

Step 2: Build the Graph and Run It with invoke()​

Replace everything in main.py with:

main.py
from typing import TypedDict

from langgraph.graph import END, START, StateGraph


class State(TypedDict):
name: str
greeting: str


def clean(state: State) -> dict:
return {"name": state["name"].strip().title()}


def greet(state: State) -> dict:
return {"greeting": "Hello, " + state["name"] + "!"}


builder = StateGraph(State)
builder.add_node("clean", clean)
builder.add_node("greet", greet)
builder.add_edge(START, "clean")
builder.add_edge("clean", "greet")
builder.add_edge("greet", END)
graph = builder.compile()

print(graph.invoke({"name": " ada lovelace "}))
  • clean returns a new name: strip() removes the spaces at both ends, and title() starts each word with a capital letter.
  • greet returns a greeting made from the name.
  • The edges run START → clean → greet → END, so greet sees the name that clean tidied.

Run it:

Terminal
uv run main.py
Output
{'name': 'Ada Lovelace', 'greeting': 'Hello, Ada Lovelace!'}

The terminal after uv run main.py with invoke: one line with the final state, name Ada Lovelace and greeting Hello, Ada Lovelace!

That's the final state, and it's right. But it doesn't show who did what: you passed in " ada lovelace ", and nothing in this line says that clean changed it.

Step 3: Stream What Each Node Returns​

Replace the last line of main.py, the print(graph.invoke(...)), with a loop over graph.stream():

main.py (last lines)
for update in graph.stream({"name": " ada lovelace "}, stream_mode="updates"):
print(update)

Run it again:

Terminal
uv run main.py
Output
{'clean': {'name': 'Ada Lovelace'}}
{'greet': {'greeting': 'Hello, Ada Lovelace!'}}

The terminal after uv run main.py with stream_mode updates: two lines, clean with name Ada Lovelace, then greet with greeting Hello, Ada Lovelace!

Each line is one node's update, in the order the nodes ran:

  • {'clean': {'name': 'Ada Lovelace'}}: clean returned only the tidied name.
  • {'greet': {'greeting': 'Hello, Ada Lovelace!'}}: greet returned only the greeting.

The graph ran exactly as before. What changed is what you see: every node's return value, labelled with the node's name. When a result looks wrong, this tells you which node to look at. The commands in this guide work unchanged in PowerShell.

The Complete File​

main.py
from typing import TypedDict

from langgraph.graph import END, START, StateGraph


class State(TypedDict):
name: str
greeting: str


def clean(state: State) -> dict:
return {"name": state["name"].strip().title()}


def greet(state: State) -> dict:
return {"greeting": "Hello, " + state["name"] + "!"}


builder = StateGraph(State)
builder.add_node("clean", clean)
builder.add_node("greet", greet)
builder.add_edge(START, "clean")
builder.add_edge("clean", "greet")
builder.add_edge("greet", END)
graph = builder.compile()

for update in graph.stream({"name": " ada lovelace "}, stream_mode="updates"):
print(update)

The complete main.py of name-greeter in a macOS-style code window: a State with name and greeting, a clean node that strips and title-cases the name, a greet node, the edges from START through clean and greet to END, and a loop that prints each update from graph.stream with stream_mode updates.

Common Mistakes​

MistakeWhat happensDo this instead
Printing what stream() returns: print(graph.stream(...))You see the generator object, such as <generator object Pregel.stream at 0xafd60b010> (the number after at changes on every run), instead of the updatesLoop over it with for, as in Step 3
Misspelling the mode: stream_mode="update"The loop prints nothing at all, and there's no errorWrite "updates". Fixed: LangGraph graph.stream() Prints Nothing and Raises No Error shows why
Using invoke() to find out which node changed a valueYou get only the final state, as in Step 2Use stream() with stream_mode="updates"

FAQ​

What does stream_mode="values" show?​

The whole state after each step, starting with your input. With this loop:

main.py (last lines)
for state in graph.stream({"name": " ada lovelace "}, stream_mode="values"):
print(state)

the same graph printed:

Output
{'name': ' ada lovelace '}
{'name': 'Ada Lovelace'}
{'name': 'Ada Lovelace', 'greeting': 'Hello, Ada Lovelace!'}

The streaming guide says that values "streams the full value of the state after each step of the graph". Use updates to see what each node changed, and values to see where the state stood after each step.

Do I have to write stream_mode="updates"?​

Not for this graph. Without stream_mode, the same loop printed the same two lines, so a graph built with StateGraph streams its updates by default. Writing it out still makes it clear what the loop prints.

What does version="v2" change?​

Every item gets the same three keys, whatever the mode: type, ns and data. With this loop:

main.py (last lines)
for part in graph.stream({"name": " ada lovelace "}, stream_mode="updates", version="v2"):
print(part)

the graph printed:

Output
{'type': 'updates', 'ns': (), 'data': {'clean': {'name': 'Ada Lovelace'}}}
{'type': 'updates', 'ns': (), 'data': {'greet': {'greeting': 'Hello, Ada Lovelace!'}}}

The update from Step 3 is now under data, type names the mode, and ns stays empty unless the graph runs subgraphs. The streaming guide notes that this format "Requires LangGraph 1.1 or later", and its own examples use it.

Conclusion​

graph.stream() with stream_mode="updates" printed one line per node: clean returned the tidied name, and greet returned the greeting. invoke() had shown only the final state.

Additional Resources​