Skip to content

Conversation

casparb
Copy link
Contributor

@casparb casparb commented Sep 8, 2025

Description

  • Replace the Mermaid graph node label escaping logic (_escape_node_label) with _to_safe_id, which converts a string into a unique, Mermaid-compatible node id. Ensures nodes with special characters always render correctly.

Before

  • Invalid characters (e.g. ) replaced with _. Causes collisions between nodes with names that are the same length and contain all non-safe characters:
_escape_node_label("开") # '_'
_escape_node_label("始") # '_'  same as above, but different character passed in. not a unique mapping.

After

_to_safe_id("开") # \5f00
_to_safe_id("始") # \59cb  unique!

Tests

  • Rename test_graph_mermaid_escape_node_label() to test_graph_mermaid_to_safe_id() and update function logic to use _to_safe_id
  • Add test_graph_mermaid_special_chars()

Issue

Fixes langchain-ai/langgraph#6036

Copy link

vercel bot commented Sep 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 11, 2025 9:05pm

Copy link

codspeed-hq bot commented Sep 8, 2025

CodSpeed WallTime Performance Report

Merging #32857 will not alter performance

Comparing caspar/mermaid-special-char (94dec3d) with master (9cc8538)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched

Copy link

codspeed-hq bot commented Sep 8, 2025

CodSpeed Instrumentation Performance Report

Merging #32857 will not alter performance

Comparing caspar/mermaid-special-char (94dec3d) with master (9cc8538)

Summary

✅ 14 untouched

@mdrxy mdrxy added the core Related to the package `langchain-core` label Sep 9, 2025
"""
Keep [a-zA-Z0-9_-] characters unchanged.
Map every other character -> \ + lowercase hex codepoint.
Result is only [a-zA-Z0-9\\_-], which is Mermaid compatible.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mermaid node ids can contain _, -, and \. Kept _ and - so slug is more human-readable. Use \ to escape code point representations.

@@ -1913,15 +1934,15 @@
graph TD;
PromptInput --> PromptTemplate;
PromptTemplate --> FakeListLLM;
Parallel_as_list_as_str_Input --> CommaSeparatedListOutputParser;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi this was Parallel<as_list,as_str>Input and the previous function implementation replaced all nonascii with _. That's why it looks cleaner. But not the approach we want.

@casparb casparb marked this pull request as ready for review September 11, 2025 20:11
@casparb casparb closed this Sep 11, 2025
@casparb casparb reopened this Sep 11, 2025
@casparb casparb force-pushed the caspar/mermaid-special-char branch from aa19ebd to d610150 Compare September 11, 2025 20:21
Copy link
Collaborator

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! Thanks for iterating

@casparb casparb merged commit 15d558f into master Sep 11, 2025
85 checks passed
@casparb casparb deleted the caspar/mermaid-special-char branch September 11, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

draw mermaid wrong when node name is Chinese text
4 participants