{"record":{"id":"8ee6537708bc3b9e","repo":"langchain-ai/langchain","slug":"invalid-draw-method-draw-method-supported-draw","errorCode":null,"errorMessage":"Invalid draw method: {draw_method}. Supported draw methods are: {supported_methods}","messagePattern":"Invalid draw method: (.+?)\\. Supported draw methods are: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/graph_mermaid.py","lineNumber":329,"sourceCode":"            )\n        )\n    elif draw_method == MermaidDrawMethod.API:\n        img_bytes = _render_mermaid_using_api(\n            mermaid_syntax,\n            output_file_path=output_file_path,\n            background_color=background_color,\n            max_retries=max_retries,\n            retry_delay=retry_delay,\n            base_url=base_url,\n            proxies=proxies,\n        )\n    else:\n        supported_methods = \", \".join([m.value for m in MermaidDrawMethod])  # type: ignore[unreachable]\n        msg = (\n            f\"Invalid draw method: {draw_method}. \"\n            f\"Supported draw methods are: {supported_methods}\"\n        )\n        raise ValueError(msg)\n\n    return img_bytes\n\n\nasync def _render_mermaid_using_pyppeteer(\n    mermaid_syntax: str,\n    output_file_path: str | None = None,\n    background_color: str | None = \"white\",\n    padding: int = 10,\n    device_scale_factor: int = 3,\n) -> bytes:\n    \"\"\"Renders Mermaid graph using Pyppeteer.\"\"\"\n    if not _HAS_PYPPETEER:\n        msg = \"Install Pyppeteer to use the Pyppeteer method: `pip install pyppeteer`.\"\n        raise ImportError(msg)\n\n    browser = await launch()\n    page = await browser.newPage()","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/graph_mermaid.py#L311-L347","documentation":"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.","triggerScenarios":"Calling draw_mermaid_png(mermaid_syntax, draw_method=\"api\") or draw_method=\"pyppeteer\" (string instead of enum), or a custom/misspelled value.","commonSituations":"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.","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"],"exampleFix":"# before\ndraw_mermaid_png(syntax, draw_method=\"api\")\n# after\nfrom langchain_core.runnables.graph_mermaid import MermaidDrawMethod\ndraw_mermaid_png(syntax, draw_method=MermaidDrawMethod.API)","handlingStrategy":"type-guard","validationCode":"from langchain_core.runnables.graph_mermaid import MermaidDrawMethod\nassert draw_method in set(MermaidDrawMethod)","typeGuard":"from typing import cast\nfrom langchain_core.runnables.graph_mermaid import MermaidDrawMethod\n\ndef is_draw_method(v: object) -> bool:\n    return isinstance(v, MermaidDrawMethod)","tryCatchPattern":"try:\n    draw_mermaid_png(syntax, draw_method=method)\nexcept ValueError as e:\n    if \"Invalid draw method\" in str(e):\n        draw_mermaid_png(syntax)  # default API method","preventionTips":["Always pass the MermaidDrawMethod enum, never a string","Type-hint your config as MermaidDrawMethod so mypy catches string values"],"tags":["graph","mermaid","png","enum","valueerror"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}