Skip to content

Update graph_mermaid.py #31577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libs/core/langchain_core/runnables/graph_mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def add_subgraph(edges: list[Edge], prefix: str) -> None:

def _escape_node_label(node_label: str) -> str:
"""Escapes the node label for Mermaid syntax."""
return re.sub(r"[^a-zA-Z-_0-9]", "_", node_label)
mermaid_special_chars = r"[\(\)\[\]\{\}<>\"'`;:&|,=#`~^%?@$/+\-\*!\.\\]"
return re.sub(mermaid_special_chars, "_", node_label)


def _generate_mermaid_graph_styles(node_colors: NodeStyles) -> str:
Expand Down
Loading