Fixed: LangChain draw_mermaid() Diagram Labels Unreadable in Dark Mode
I drew a LangChain agent with agent.get_graph().draw_mermaid() and viewed the diagram in dark mode, and three of its four labels almost vanished: light grey text on pale boxes. The Mermaid text colours the boxes but leaves the text colour to the renderer's theme, and dark themes draw light text. A NodeStyles with a dark text colour and a white start box made every label readable, in dark mode and in light.
What I Was Doing
I had an agent with one tool, get_weather, and printed its graph as Mermaid text, the way How to Draw a LangChain Agent as a Mermaid Diagram in Python does, with langchain 1.5.2 and langchain-core 1.8.5 on Python 3.14.10:
from langchain.agents import create_agent
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"It's always sunny in {city}!"
agent = create_agent(model="anthropic:claude-opus-5-5", tools=[get_weather])
print(agent.get_graph().draw_mermaid())
uv run main.py
---
config:
flowchart:
curve: linear
---
graph TD;
__start__([<p>__start__</p>]):::first
model(model)
tools(tools<hr/><small><em>__tools = get_weather</em></small>)
__end__([<p>__end__</p>]):::last
__start__ --> model;
model -.-> __end__;
model -.-> tools;
tools -.-> model;
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc
Drawing an agent doesn't call the model, so none of this needs an API key.
Then I viewed the text as a diagram in dark mode. The diagrams in this post come from the Mermaid Live Editor, Mermaid's own editor in the browser, running Mermaid 12.4.0. I switched it to dark mode with the sun button at its bottom right, labelled Switch to dark theme.
What I Expected
Four readable labels, __start__, model, tools (with get_weather under it) and __end__, as in light mode, where the same text draws dark labels on pale boxes.
What I Got
Only __start__ was readable. model, tools, its tool list and __end__ were light grey on pale boxes:

Mermaid's classic dark theme, which its theming guide says goes well with dark-colored elements or dark-mode, drew it the same way.
What I Checked
1. The Mermaid text sets the box colours, not the text colour
The last three lines of the output style the nodes:
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc
A classDef line defines a class of styles, and :::first and :::last in the node lines attach the first class to __start__ and the last class to __end__. The styles are CSS properties: fill is a box's colour, and the text's colour is color, as in this line from Mermaid's flowchart guide: style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5. These three lines set fill and never color. fill-opacity:0 makes the start node's box see-through, so __start__'s label sits on the page itself, which is why it stayed readable.
These styles are the defaults of NodeStyles in langchain-core. Its API reference gives them: fill:#f2f0ff,line-height:1.2 for default, fill-opacity:0 for first and fill:#bfb6fc for last.
2. Dark themes draw node text in a light colour
Mermaid's theming guide gives the text colour of nodes, primaryTextColor, as calculated from darkMode #ddd/#333: light grey in dark mode, dark grey otherwise. The editor's dark mode had set the diagram's theme to redux-dark-color, which the guide calls The dark counterpart of redux-color. So in dark mode, light text landed on the light #f2f0ff and #bfb6fc boxes.
3. with_styles=False made the labels readable but lost the details
draw_mermaid() has a with_styles option, which its API reference describes as Whether to include styles in the syntax. I changed the last line of main.py to:
print(agent.get_graph().draw_mermaid(with_styles=False))
uv run main.py
graph TD;
__start__ --> model;
model -.-> __end__;
model -.-> tools;
tools -.-> model;
It left out more than the colours: the config at the top and every node line went too. Drawn in dark mode, the labels were readable, but the nodes were plain boxes and tools no longer listed get_weather:

So I put the styles back and looked for a way to change them instead.
4. My first try: a dark text colour on the two filled styles
draw_mermaid() also takes node_colors, which its API reference describes as The colors of the nodes. It takes a NodeStyles. I kept the default fills and added a dark grey text colour, color:#333, to the two styles that fill their boxes, with from langchain_core.runnables.graph import NodeStyles at the top of main.py:
styles = NodeStyles(
default="fill:#f2f0ff,line-height:1.2,color:#333",
last="fill:#bfb6fc,color:#333",
)
print(agent.get_graph().draw_mermaid(node_colors=styles))
classDef default fill:#f2f0ff,line-height:1.2,color:#333
classDef first fill-opacity:0
classDef last fill:#bfb6fc,color:#333
model, tools and __end__ became readable, and __start__ vanished instead:

The drawing showed why. Mermaid's flowchart guide says a class named default will be assigned to all classes without specific class definitions, which reads as if a node with a class of its own, such as __start__, doesn't get it. But in the drawing, the start node's element carries the classes node default first, and the end node's carries node default last: default reached every node, and first and last added their own styles on top. So my color:#333 on default reached __start__ too, and its see-through box put dark grey text on the dark page.
Why It Happens
draw_mermaid() colours the boxes light, #f2f0ff for most nodes and #bfb6fc for __end__, and leaves the text colour to the renderer's theme. A light theme draws dark text, which reads well on those boxes. A dark theme draws light text, which doesn't. Only __start__ escapes, because its box is see-through.
The Fix
Pass node_colors a NodeStyles that gives every label a dark colour and the start node a white box. Replace everything in main.py with:
from langchain.agents import create_agent
from langchain_core.runnables.graph import NodeStyles
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"It's always sunny in {city}!"
agent = create_agent(model="anthropic:claude-opus-5-5", tools=[get_weather])
styles = NodeStyles(
default="fill:#f2f0ff,line-height:1.2,color:#333",
first="fill:#fff",
)
print(agent.get_graph().draw_mermaid(node_colors=styles))

defaultkeeps the default fill and line height and addscolor:#333. Every node carries thedefaultclass, so every label turns dark grey.firstswaps the see-through box for a white one,fill:#fff, so__start__'s dark label has a light box behind it. On a plain white page, a white box looks the same as a see-through one.lastisn't passed, so it keeps its default,fill:#bfb6fc, and its label takes the dark grey fromdefault.
Run it:
uv run main.py
---
config:
flowchart:
curve: linear
---
graph TD;
__start__([<p>__start__</p>]):::first
model(model)
tools(tools<hr/><small><em>__tools = get_weather</em></small>)
__end__([<p>__end__</p>]):::last
__start__ --> model;
model -.-> __end__;
model -.-> tools;
tools -.-> model;
classDef default fill:#f2f0ff,line-height:1.2,color:#333
classDef first fill:#fff
classDef last fill:#bfb6fc
Only the classDef default and classDef first lines changed.
Let the Theme Colour the Boxes Instead
If you'd rather have a dark diagram in dark mode, take the fills out instead, so the theme colours the boxes and their text together. In the fix's main.py, replace the styles lines with:
styles = NodeStyles(
default="line-height:1.2",
last="line-height:1.2",
)
classDef default line-height:1.2
classDef first fill-opacity:0
classDef last line-height:1.2
first keeps its see-through box, and last gets the same style as default, so __end__ loses its purple. In dark mode, the theme drew dark boxes with light labels:

In light mode, it drew white boxes with dark labels.
After the Fix
With the fix, the editor's dark mode drew every label in dark grey, on the default box colours:

In light mode, the drawing barely changes. The labels are dark grey instead of the theme's dark navy, and the start box is white, so the editor's background dots no longer show through it:

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Calling draw_mermaid(with_styles=False) | The labels read, but the node lines are gone: plain boxes, and no tool list under tools | Pass node_colors |
Adding color:#333 to default and leaving first see-through | __start__ vanishes in dark mode | Give first a fill, such as fill:#fff |
| Editing the printed text by hand | The next draw_mermaid() call prints the old colours again | Pass node_colors, so every drawing gets the change |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
model, tools and __end__ hard to read in dark mode | Light boxes with a dark theme's light text | NodeStyles with color:#333 on default and fill:#fff on first |
Only __start__ hard to read in dark mode | A dark text colour with a see-through start box | Give first a fill |
tools lists no tools | with_styles=False | Remove it and pass node_colors |
FAQ
Does the fix change the drawing in light mode?
Only slightly. The box colours stay the defaults, the labels turn from the theme's dark navy to dark grey, and the start box turns white, so a patterned background, such as the Mermaid Live Editor's dots, no longer shows through it.
Does drawing the agent need an API key?
No. Drawing an agent doesn't call the model, and every run in this post ran without one.
Can I use other colours?
Yes. Pick text and box colours that contrast, dark text on light boxes or light text on dark ones, and give the start node a filled box too, so every label reads on a light page and on a dark one.
Conclusion
draw_mermaid() colours an agent's boxes light and leaves the text colour to the theme, so in dark mode the labels of model, tools and __end__ nearly vanished. Passing node_colors=NodeStyles(default="fill:#f2f0ff,line-height:1.2,color:#333", first="fill:#fff") made every label readable in dark mode, and changed light mode only slightly.
Additional Resources
- Graph.draw_mermaid —
node_colors,with_stylesand the other options. - NodeStyles — the three classes and their default styles.
- Styling a node — Mermaid's
styleandclassDeflines. - Default class — what Mermaid's guide says about a class named
default. - Theme variables —
primaryTextColorand the other theme colours. - Mermaid Live Editor — Mermaid's editor in the browser, with light and dark modes.
