Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
baur-krykpayev authored Jun 21, 2024
2 parents 74eb7d3 + 9ac302c commit b2c103f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libs/core/langchain_core/runnables/graph_mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def draw_mermaid(

def _escape_node_label(node_label: str) -> str:
"""Escapes the node label for Mermaid syntax."""
return re.sub(r"[^a-zA-Z-_]", "_", node_label)
return re.sub(r"[^a-zA-Z-_0-9]", "_", node_label)


def _adjust_mermaid_edge(
Expand Down
9 changes: 9 additions & 0 deletions libs/core/tests/unit_tests/runnables/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from langchain_core.output_parsers.xml import XMLOutputParser
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.runnables.base import Runnable, RunnableConfig
from langchain_core.runnables.graph_mermaid import _escape_node_label
from tests.unit_tests.stubs import AnyStr


Expand Down Expand Up @@ -734,3 +735,11 @@ def invoke(
assert runnable.invoke(1) == 1
# check whether runnable.get_graph works
runnable.get_graph()


def test_graph_mermaid_escape_node_label() -> None:
"""Test that node labels are correctly preprocessed for draw_mermaid"""
assert _escape_node_label("foo") == "foo"
assert _escape_node_label("foo-bar") == "foo-bar"
assert _escape_node_label("foo_1") == "foo_1"
assert _escape_node_label("#foo*&!") == "_foo___"

0 comments on commit b2c103f

Please sign in to comment.