Conditional workflows can be difficult to follow from node functions alone. LangGraph exposes a compiled graph as Mermaid text, which a local Chromium browser can render into a PNG diagram on Linux.

A diagram shows possible routes rather than the path taken by a particular invocation. Conditional edges need a destination mapping or a return annotation such as Literal, because without either the diagram loses the routes and shows a false edge to __end__.

The default PNG renderer sends diagram text to Mermaid.ink. Local rendering with Pyppeteer avoids that service, but still needs a browser and a Mermaid JavaScript bundle. Downloading the dependencies requires network access; rendering from the saved bundle does not require an external diagram service.

Steps to visualize a LangGraph graph:

  1. Open conditional_route.py from Add conditional routing to a LangGraph graph, or your own module that compiles a graph, in your text editor.

    Rendering needs curl, LangGraph in an active environment from Install LangGraph with pip, and Chromium from the guide for Ubuntu, Fedora, CentOS Stream or RHEL, or SUSE. Debian provides the chromium package through APT. Fedora 45 defaults to Python 3.15, which has no prebuilt zstandard package for LangGraph's dependencies, so install python3.14 there and create the environment with it. Tested with LangGraph 1.2.20 on Debian 13, Ubuntu 26.04, Fedora 45, CentOS Stream 10, and openSUSE Leap 16.

  2. Move the for score in (84, 42): loop at the end of the file, or any top-level invocations and prints in your own module, under a __main__ guard.
    if __name__ == "__main__":
        for score in (84, 42):
            final_state = graph.invoke({"score": score})
            print(
                f"score={score} route={final_state['result']} "
                f"message={final_state['message']}"
            )

    Importing a module runs its top-level code, so printed lines would land in graph.mmd and stop the renderer with No diagram type detected.

  3. Save the module in your text editor.
  4. Export Mermaid text from the compiled graph object, replacing conditional_route and graph with your own module and variable names if they differ.
    $ python -c 'from conditional_route import graph; print(graph.get_graph().draw_mermaid())' > graph.mmd

    Exporting and rendering inspect the graph without invoking its nodes.

  5. Inspect graph.mmd for the nodes and directed edges declared in the graph.
    $ cat graph.mmd
    ---
    config:
      flowchart:
        curve: linear
    ---
    graph TD;
    	__start__([<p>__start__</p>]):::first
    	evaluate(evaluate)
    	accept(accept)
    	reject(reject)
    	__end__([<p>__end__</p>]):::last
    	__start__ --> evaluate;
    	evaluate -. &nbsp;passed&nbsp; .-> accept;
    	evaluate -. &nbsp;failed&nbsp; .-> reject;
    	accept --> __end__;
    	reject --> __end__;
    	classDef default fill:#f2f0ff,line-height:1.2
    	classDef first fill-opacity:0
    	classDef last fill:#bfb6fc

    Node names and route labels depend on the graph. Here, evaluate has two conditional edges labeled passed and failed, while each branch has a solid edge to __end__. Tested with LangGraph 1.2.20. A solid edge from the routing node to __end__, with no edges into its branch nodes, means the conditional route declares no destinations.

  6. Create a separate Python environment for the local renderer.
    $ python -m venv .render-venv

    Pyppeteer's WebSocket dependency constraints conflict with current LangGraph dependencies. A separate environment keeps the renderer's packages out of the graph environment.

  7. Install Pyppeteer in the renderer environment.
    $ .render-venv/bin/python -m pip install pyppeteer==2.0.0

    Pyppeteer is unmaintained. Its automatic Linux Chromium download targets x86-64, so the renderer below explicitly uses the installed system browser instead.

  8. Download the Mermaid browser bundle into the project directory.
    $ curl --fail --location https://cdn.jsdelivr.net/npm/mermaid@12.3.0/dist/mermaid.min.js --output mermaid.min.js

    The pinned bundle is loaded from disk during rendering. The default LangGraph Pyppeteer helper loads Mermaid from a CDN on each run.

  9. Create render_graph.py in the project directory using your text editor.
    render_graph.py
    import asyncio
    from pathlib import Path
    from shutil import which
     
    from pyppeteer import launch
     
    mermaid_text = Path("graph.mmd").read_text()
    chromium = which("chromium") or which("chromium-browser")
    if chromium is None:
        raise RuntimeError("Chromium was not found on PATH.")

    Fedora and CentOS Stream name the executable chromium-browser, while Debian, Ubuntu, and openSUSE provide chromium.

  10. Append the browser setup below the Chromium check in render_graph.py.
    async def render():
        browser = await launch(executablePath=chromium)
        try:
            page = await browser.newPage()
            await page.setViewport({"width": 1000, "height": 1000})
            await page.addScriptTag({"path": "mermaid.min.js"})
            await page.evaluate(
                "mermaid.initialize({startOnLoad: false})"
            )

    The browser loads the local bundle before receiving the Mermaid text. The viewport leaves room for the diagram, while the final capture is cropped to the SVG element.

  11. Append the rendering and PNG capture code immediately after the Mermaid initialization call.
            await page.evaluate("""async (text) => {
                const {svg} = await mermaid.render('graph', text);
                document.body.innerHTML = svg;
            }""", mermaid_text)
            diagram = await page.querySelector("svg")
            await diagram.screenshot({"path": "graph.png"})
        finally:
            await browser.close()
     
     
    asyncio.run(render())

    The await waits for Mermaid to finish drawing before capture. The browser closes even when parsing or capture fails.

  12. Save render_graph.py in your text editor.
  13. Run the renderer from the project directory.
    $ PYPPETEER_HOME=$PWD/.pyppeteer .render-venv/bin/python render_graph.py

    A successful run writes graph.png beside graph.mmd. Existing graph.png content is replaced. PYPPETEER_HOME keeps Pyppeteer's temporary browser profile in the project because the Ubuntu Chromium snap cannot write to the default location under ~/.local, and that snap needs the project in a non-hidden folder of your home directory. A Browser closed unexpectedly error, usually followed by an Event loop is closed traceback, hides Chromium's own message, which chromium --headless --dump-dom about:blank prints, using chromium-browser on Fedora and CentOS Stream. Root sessions and containers commonly report a sandbox failure there, and disabling the sandbox weakens browser isolation.

  14. Inspect graph.png in your image viewer for the nodes and conditional routes listed in graph.mmd.

    Example output:

    The pictured graph has __start__ → evaluate, dotted passed and failed routes to accept and reject, and solid edges from both branches to __end__. A blank image, missing node, or extra route needs correction before the diagram represents the graph. Boxes with no text mean the system has no fonts installed.

Share this guide