langchain-ai/langchain · error · ValueError
Invalid draw method: {draw_method}. Supported draw methods a
Error message
Invalid draw method: {draw_method}. Supported draw methods are: {supported_methods} What it means
draw_mermaid_png() dispatches on the draw_method argument and only accepts MermaidDrawMethod enum members (PYPPETEER, API). Any other value falls through to this ValueError listing the supported methods. Passing the method as a plain string fails the enum equality check and lands here.
Source
Thrown at libs/core/langchain_core/runnables/graph_mermaid.py:329
)
)
elif draw_method == MermaidDrawMethod.API:
img_bytes = _render_mermaid_using_api(
mermaid_syntax,
output_file_path=output_file_path,
background_color=background_color,
max_retries=max_retries,
retry_delay=retry_delay,
base_url=base_url,
proxies=proxies,
)
else:
supported_methods = ", ".join([m.value for m in MermaidDrawMethod]) # type: ignore[unreachable]
msg = (
f"Invalid draw method: {draw_method}. "
f"Supported draw methods are: {supported_methods}"
)
raise ValueError(msg)
return img_bytes
async def _render_mermaid_using_pyppeteer(
mermaid_syntax: str,
output_file_path: str | None = None,
background_color: str | None = "white",
padding: int = 10,
device_scale_factor: int = 3,
) -> bytes:
"""Renders Mermaid graph using Pyppeteer."""
if not _HAS_PYPPETEER:
msg = "Install Pyppeteer to use the Pyppeteer method: `pip install pyppeteer`."
raise ImportError(msg)
browser = await launch()
page = await browser.newPage()View on GitHub (pinned to e32fa9a52e)
Solutions
- Pass the enum: from langchain_core.runnables.graph_mermaid import MermaidDrawMethod; draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.API)
- If you must accept strings from config, convert first: MermaidDrawMethod(str_value.lower())
- Omit draw_method to use the default MermaidDrawMethod.API
Example fix
# before draw_mermaid_png(syntax, draw_method="api") # after from langchain_core.runnables.graph_mermaid import MermaidDrawMethod draw_mermaid_png(syntax, draw_method=MermaidDrawMethod.API)
Defensive patterns
Strategy: type-guard
Validate before calling
from langchain_core.runnables.graph_mermaid import MermaidDrawMethod assert draw_method in set(MermaidDrawMethod)
Type guard
from typing import cast
from langchain_core.runnables.graph_mermaid import MermaidDrawMethod
def is_draw_method(v: object) -> bool:
return isinstance(v, MermaidDrawMethod) Try / catch
try:
draw_mermaid_png(syntax, draw_method=method)
except ValueError as e:
if "Invalid draw method" in str(e):
draw_mermaid_png(syntax) # default API method Prevention
- Always pass the MermaidDrawMethod enum, never a string
- Type-hint your config as MermaidDrawMethod so mypy catches string values
When it happens
Trigger: Calling draw_mermaid_png(mermaid_syntax, draw_method="api") or draw_method="pyppeteer" (string instead of enum), or a custom/misspelled value.
Common situations: Users copying example code that quotes the method; upgrading code that used strings in older versions; IDE autocompleting the value instead of the enum member.
Related errors
- Found duplicate subgraph '{subgraph}' -- this likely means t
- Install Pyppeteer to use the Pyppeteer method: `pip install
- Install the `requests` module to use the Mermaid.INK API: `p
- Failed to reach {base_url} API while trying to render your g
- Failed to reach {base_url} API while trying to render your g
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/8ee6537708bc3b9e.
Report an issue: GitHub.