Home / Function/ _to_safe_id() — langchain Function Reference

_to_safe_id() — langchain Function Reference

Architecture documentation for the _to_safe_id() function in graph_mermaid.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  776b523a_707b_6be9_ae9a_137ca8570849["_to_safe_id()"]
  c545ef44_a033_15ff_e016_18af37277247["graph_mermaid.py"]
  776b523a_707b_6be9_ae9a_137ca8570849 -->|defined in| c545ef44_a033_15ff_e016_18af37277247
  6f5bf1ec_e14e_f271_08a5_0bc96c21c52a["draw_mermaid()"]
  6f5bf1ec_e14e_f271_08a5_0bc96c21c52a -->|calls| 776b523a_707b_6be9_ae9a_137ca8570849
  style 776b523a_707b_6be9_ae9a_137ca8570849 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/graph_mermaid.py lines 255–266

def _to_safe_id(label: str) -> str:
    """Convert a string into a Mermaid-compatible node id.

    Keep [a-zA-Z0-9_-] characters unchanged.
    Map every other character -> backslash + lowercase hex codepoint.

    Result is guaranteed to be unique and Mermaid-compatible,
    so nodes with special characters always render correctly.
    """
    allowed = string.ascii_letters + string.digits + "_-"
    out = [ch if ch in allowed else "\\" + format(ord(ch), "x") for ch in label]
    return "".join(out)

Domain

Subdomains

Called By

Frequently Asked Questions

What does _to_safe_id() do?
_to_safe_id() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph_mermaid.py.
Where is _to_safe_id() defined?
_to_safe_id() is defined in libs/core/langchain_core/runnables/graph_mermaid.py at line 255.
What calls _to_safe_id()?
_to_safe_id() is called by 1 function(s): draw_mermaid.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free