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
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 PNGThe state
Build a small graph first, so there is something to draw. It has one node that doubles a number.
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
x: intBuilding the graph
Add the node and wire it between START and END, then compile.
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.
print(list(graph.get_graph().nodes)) # your node plus the two LangGraph addsThe node list in a run
The same pieces in one file, ready to run.
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.
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;.nodeslists 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
| Call | Gives you |
|---|---|
draw_mermaid() | Mermaid text, to paste into a viewer or docs |
draw_mermaid_png() | A rendered PNG of the graph |
get_graph().nodes | The 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.
Related
- Previous: add_edge: two steps in a row
- Next: Conditional edges: choosing a path
- 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.