Home / Function/ draw_mermaid() — langchain Function Reference

draw_mermaid() — langchain Function Reference

Architecture documentation for the draw_mermaid() function in graph.py from the langchain codebase.

Function python LangChainCore Runnables calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  b9f04a0f_6507_1a21_7a91_357a589c2c3a["draw_mermaid()"]
  646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"]
  b9f04a0f_6507_1a21_7a91_357a589c2c3a -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90
  e151d2f1_d848_ea86_47fa_455730afbb7a["draw_mermaid_png()"]
  e151d2f1_d848_ea86_47fa_455730afbb7a -->|calls| b9f04a0f_6507_1a21_7a91_357a589c2c3a
  9f553f07_a134_96b2_5d30_cde7bee5fd6f["reid()"]
  b9f04a0f_6507_1a21_7a91_357a589c2c3a -->|calls| 9f553f07_a134_96b2_5d30_cde7bee5fd6f
  202074c8_de09_73dd_415c_edea3bae12f1["first_node()"]
  b9f04a0f_6507_1a21_7a91_357a589c2c3a -->|calls| 202074c8_de09_73dd_415c_edea3bae12f1
  6b97cc3d_1205_0325_4d44_e903570471b2["last_node()"]
  b9f04a0f_6507_1a21_7a91_357a589c2c3a -->|calls| 6b97cc3d_1205_0325_4d44_e903570471b2
  style b9f04a0f_6507_1a21_7a91_357a589c2c3a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/graph.py lines 575–628

    def draw_mermaid(
        self,
        *,
        with_styles: bool = True,
        curve_style: CurveStyle = CurveStyle.LINEAR,
        node_colors: NodeStyles | None = None,
        wrap_label_n_words: int = 9,
        frontmatter_config: dict[str, Any] | None = None,
    ) -> str:
        """Draw the graph as a Mermaid syntax string.

        Args:
            with_styles: Whether to include styles in the syntax.
            curve_style: The style of the edges.
            node_colors: The colors of the nodes.
            wrap_label_n_words: The number of words to wrap the node labels at.
            frontmatter_config: Mermaid frontmatter config.
                Can be used to customize theme and styles. Will be converted to YAML and
                added to the beginning of the mermaid graph.

                See more here: https://mermaid.js.org/config/configuration.html.

                Example config:

                ```python
                {
                    "config": {
                        "theme": "neutral",
                        "look": "handDrawn",
                        "themeVariables": {"primaryColor": "#e2e2e2"},
                    }
                }
                ```
        Returns:
            The Mermaid syntax string.
        """
        # Import locally to prevent circular import
        from langchain_core.runnables.graph_mermaid import draw_mermaid  # noqa: PLC0415

        graph = self.reid()
        first_node = graph.first_node()
        last_node = graph.last_node()

        return draw_mermaid(
            nodes=graph.nodes,
            edges=graph.edges,
            first_node=first_node.id if first_node else None,
            last_node=last_node.id if last_node else None,
            with_styles=with_styles,
            curve_style=curve_style,
            node_styles=node_colors,
            wrap_label_n_words=wrap_label_n_words,
            frontmatter_config=frontmatter_config,
        )

Domain

Subdomains

Called By

Frequently Asked Questions

What does draw_mermaid() do?
draw_mermaid() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is draw_mermaid() defined?
draw_mermaid() is defined in libs/core/langchain_core/runnables/graph.py at line 575.
What does draw_mermaid() call?
draw_mermaid() calls 3 function(s): first_node, last_node, reid.
What calls draw_mermaid()?
draw_mermaid() is called by 1 function(s): draw_mermaid_png.

Analyze Your Own Codebase

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

Try Supermodel Free