langchain-ai/langgraph · error · ValueError

No cache is set for this graph. Cannot clear cache.

Error message

No cache is set for this graph. Cannot clear cache.

What it means

Raised by clear_cache when the graph has no cache configured (cache is None). There is no cache to clear, so the operation is refused rather than silently doing nothing. Configure a cache on the graph (compile with cache=...) before calling clear_cache.

Solutions

  1. Compile the graph with a cache, e.g. compile(cache=BaseCache(...))
  2. Skip calling clear_cache on cache-less graphs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at libs/langgraph/langgraph/pregel/main.py:4139 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26). Data as JSON: /api/errors/f6c46164c45e5893. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/pregel/main.py:4139

                    chunks.append(chunk)

        if stream_mode == "values":
            if version == "v2":
                return GraphOutput(value=latest, interrupts=tuple(interrupts))
            if interrupts:
                return (
                    {**latest, INTERRUPT: interrupts}
                    if isinstance(latest, dict)
                    else {INTERRUPT: interrupts}
                )
            return latest
        else:
            return chunks

    def clear_cache(self, nodes: Sequence[str] | None = None) -> None:
        """Clear the cache for the given nodes."""
        if not self.cache:
            raise ValueError("No cache is set for this graph. Cannot clear cache.")
        nodes = nodes or self.nodes.keys()
        # collect namespaces to clear
        namespaces: list[tuple[str, ...]] = []
        for node in nodes:
            if node in self.nodes:
                namespaces.append(
                    (
                        CACHE_NS_WRITES,
                        (identifier(self.nodes[node]) or "__dynamic__"),
                        node,
                    ),
                )
        # clear cache
        self.cache.clear(namespaces)

    async def aclear_cache(self, nodes: Sequence[str] | None = None) -> None:
        """Asynchronously clear the cache for the given nodes."""
        if not self.cache:

View on GitHub (pinned to 38031739e5)