Skip to content

Conversation

JadenKim-dev
Copy link

@JadenKim-dev JadenKim-dev commented Oct 9, 2025

When rendering a graph using mermaid, if the node name contains _node, such as answer_node, the following error occurs and rendering fails.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], line 22
     19 graph = graph.compile()
     21 # View
---> 22 display(Image(graph.get_graph().draw_mermaid_png()))

File ~/project/langchain-academy/lc-academy-env/lib/python3.13/site-packages/langchain_core/runnables/graph.py:704, in Graph.draw_mermaid_png(self, curve_style, node_colors, wrap_label_n_words, output_file_path, draw_method, background_color, padding, max_retries, retry_delay, frontmatter_config, base_url)
    694 from langchain_core.runnables.graph_mermaid import (  # noqa: PLC0415
    695     draw_mermaid_png,
    696 )
    698 mermaid_syntax = self.draw_mermaid(
    699     curve_style=curve_style,
    700     node_colors=node_colors,
    701     wrap_label_n_words=wrap_label_n_words,
    702     frontmatter_config=frontmatter_config,
    703 )
--> 704 return draw_mermaid_png(
    705     mermaid_syntax=mermaid_syntax,
    706     output_file_path=output_file_path,
    707     draw_method=draw_method,
    708     background_color=background_color,
    709     padding=padding,
    710     max_retries=max_retries,
    711     retry_delay=retry_delay,
    712     base_url=base_url,
    713 )

File ~/project/langchain-academy/lc-academy-env/lib/python3.13/site-packages/langchain_core/runnables/graph_mermaid.py:322, in draw_mermaid_png(mermaid_syntax, output_file_path, draw_method, background_color, padding, max_retries, retry_delay, base_url)
    316     img_bytes = asyncio.run(
    317         _render_mermaid_using_pyppeteer(
    318             mermaid_syntax, output_file_path, background_color, padding
    319         )
    320     )
    321 elif draw_method == MermaidDrawMethod.API:
--> 322     img_bytes = _render_mermaid_using_api(
    323         mermaid_syntax,
    324         output_file_path=output_file_path,
    325         background_color=background_color,
    326         max_retries=max_retries,
    327         retry_delay=retry_delay,
    328         base_url=base_url,
    329     )
    330 else:
    331     supported_methods = ", ".join([m.value for m in MermaidDrawMethod])

File ~/project/langchain-academy/lc-academy-env/lib/python3.13/site-packages/langchain_core/runnables/graph_mermaid.py:480, in _render_mermaid_using_api(mermaid_syntax, output_file_path, background_color, file_type, max_retries, retry_delay, base_url)
    475     # For other status codes, fail immediately
    476     msg = (
    477         f"Failed to reach {base_url} API while trying to render "
    478         f"your graph. Status code: {response.status_code}.\n\n"
    479     ) + error_msg_suffix
--> 480     raise ValueError(msg)
    482 except (requests.RequestException, requests.Timeout) as e:
    483     if attempt < max_retries:
    484         # Exponential backoff with jitter

ValueError: Failed to reach https://mermaid.ink/ API while trying to render your graph. Status code: 204.

To resolve this issue:
1. Check your internet connection and try again
2. Try with higher retry settings: `draw_mermaid_png(..., max_retries=5, retry_delay=2.0)`
3. Use the Pyppeteer rendering method which will render your graph locally in a browser: `draw_mermaid_png(..., draw_method=MermaidDrawMethod.PYPPETEER)`

I modified it to render successfully by changing the node names to answer_node -> answer, thinking_node -> thinking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant