LangGraphLangGraph 1.2 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson →

draw_mermaid: seeing your graph

graph.get_graph().draw_mermaid() returns a Mermaid diagram of your graph as text, so you can see the nodes and edges you wired.

Last updated: 27 Sep, 2026 · LangGraph 1.2

When a run goes to the wrong node, the first thing to check is the graph itself. Drawing it shows the edges you wrote, including the __start__ and __end__ that LangGraph adds for you.

The draw_mermaid call

python
print(graph.get_graph().draw_mermaid())    # Mermaid text you can paste into a viewer
graph.get_graph().draw_mermaid_png()        # the same diagram as a PNG

The state

Build a small graph first, so there is something to draw. It has one node that doubles a number.

python
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    x: int

Building the graph

Add the node and wire it between START and END, then compile.

python
b = StateGraph(State)
b.add_node("double", lambda s: {"x": s["x"] * 2})
b.add_edge(START, "double")
b.add_edge("double", END)
graph = b.compile()

Listing the nodes

Now read the structure back. get_graph().nodes lists every node, including the __start__ and __end__ that LangGraph adds around yours.

python
print(list(graph.get_graph().nodes))   # your node plus the two LangGraph adds

The node list in a run

The same pieces in one file, ready to run.

Example
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    x: int

b = StateGraph(State)
b.add_node("double", lambda s: {"x": s["x"] * 2})
b.add_edge(START, "double")
b.add_edge("double", END)
graph = b.compile()

print(list(graph.get_graph().nodes))

See the diagram text

draw_mermaid() turns the same graph into Mermaid text. Paste it into any Mermaid viewer to see the picture.

Example
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    x: int

b = StateGraph(State)
b.add_node("double", lambda s: {"x": s["x"] * 2})
b.add_edge(START, "double")
b.add_edge("double", END)
graph = b.compile()

print(graph.get_graph().draw_mermaid())

What each call gives back

  • get_graph() gives the compiled structure; .nodes lists every node, including the __start__ and __end__ LangGraph adds.
  • draw_mermaid() turns that structure into Mermaid text; paste it into any Mermaid viewer to see the diagram.
  • draw_mermaid_png() renders the same diagram straight to a PNG.

Text vs image

CallGives you
draw_mermaid()Mermaid text, to paste into a viewer or docs
draw_mermaid_png()A rendered PNG of the graph
get_graph().nodesThe list of node names, for a quick check

When to draw the graph

  • Confirming a graph is wired the way you meant before you run it.
  • Putting a picture of your agent in a README or a review.
Watch out. A node you added but never connected with an edge still shows, unreachable. If a step never runs, the diagram usually shows the missing edge.
Try it yourself
  • Print the node list for a two-node graph and find __start__ and __end__.
  • Paste draw_mermaid() output into a Mermaid viewer.

Little by little, you're building something great.