Skip to main content

Fixed: LangChain draw_mermaid() Diagram Labels Unreadable in Dark Mode

· 12 min read
Jagdish Kumawat
Founder @ Dewiride

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:

main.py
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())
Terminal
uv run main.py
Output
---
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:

The Mermaid Live Editor in dark mode drawing the agent: start is readable in a see-through box, but the labels model, tools, __tools = get_weather and end are light grey on pale lavender and purple boxes and nearly invisible.

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:

Output (last three lines)
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:

main.py (last line)
print(agent.get_graph().draw_mermaid(with_styles=False))
Terminal
uv run main.py
Output
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:

The with_styles=False output drawn in dark mode: four plain dark rectangles, start, model, tools and end, with readable light labels, but no rounded start and end shapes and no tool list under tools.

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:

main.py (the last lines)
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))
Output (last three lines)
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 diagram after adding color:#333 to the default and last styles, in dark mode: model, tools with get_weather and end now have dark readable labels, but start is dark grey on the dark background and hard to see.

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:

main.py
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))

The fixed main.py in a macOS-style code window: an agent with the get_weather tool, a NodeStyles with default set to fill:#f2f0ff,line-height:1.2,color:#333 and first set to fill:#fff, and a print of draw_mermaid(node_colors=styles).

  • default keeps the default fill and line height and adds color:#333. Every node carries the default class, so every label turns dark grey.
  • first swaps 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.
  • last isn't passed, so it keeps its default, fill:#bfb6fc, and its label takes the dark grey from default.

Run it:

Terminal
uv run main.py
Output
---
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:

main.py (the styles)
styles = NodeStyles(
default="line-height:1.2",
last="line-height:1.2",
)
Output (last three lines)
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:

The theme-coloured version in dark mode: start in a see-through rounded box, model, tools and end in dark boxes, and every label light and readable, with __tools = get_weather under tools.

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:

The fixed diagram in the Mermaid Live Editor's dark mode: start in a white box, model and tools in pale lavender boxes, end in a purple box, all with dark readable labels, including __tools = get_weather.

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:

The fixed diagram in the Mermaid Live Editor's light mode: start in a white box, model and tools in pale lavender boxes and end in a purple box, all with dark grey labels, on the editor's dotted white background.

Common Mistakes​

MistakeWhat happensDo this instead
Calling draw_mermaid(with_styles=False)The labels read, but the node lines are gone: plain boxes, and no tool list under toolsPass node_colors
Adding color:#333 to default and leaving first see-through__start__ vanishes in dark modeGive first a fill, such as fill:#fff
Editing the printed text by handThe next draw_mermaid() call prints the old colours againPass node_colors, so every drawing gets the change

Troubleshooting​

SymptomLikely causeFix
model, tools and __end__ hard to read in dark modeLight boxes with a dark theme's light textNodeStyles with color:#333 on default and fill:#fff on first
Only __start__ hard to read in dark modeA dark text colour with a see-through start boxGive first a fill
tools lists no toolswith_styles=FalseRemove 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​