# The best way in LangGraph to control flow after retries exhausted

**URL:** <https://forum.langchain.com/t/the-best-way-in-langgraph-to-control-flow-after-retries-exhausted/1574>\
**Category:** LangGraph\
**Tags:** python-help\
**Created:** [September 18, 2025, 7:07am UTC](https://forum.langchain.com/t/the-best-way-in-langgraph-to-control-flow-after-retries-exhausted/1574 "2025-09-18T07:07:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh1205](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/utkarsh1205/32/1012_2.png) [@utkarsh1205](https://forum.langchain.com/u/utkarsh1205)\
**Post date:** [September 18, 2025, 7:07am UTC](https://forum.langchain.com/t/the-best-way-in-langgraph-to-control-flow-after-retries-exhausted/1574/1 "2025-09-18T07:07:06Z")

</div>

What’s the best to control the flow of the graph when a retriable node exhausts all the retries.

We can apply Retry policies to nodes in langgraph like so -  
builder.add\_node( “node\_name”, node\_function, retry\_policy=RetryPolicy(), )

Now, if I want to redirect the flow to another node when all retries are exhausted (instead of raising that error), I would not use the above retry\_policy parameter. Instead I would create my own retry wrapper, wrap it around my method I am trying to execute and call that method in my langgraph node. Inside the langgraph node I handle the retry exhausted error.

Is there a simpler pattern available in LangGraph’s Graph API to help me do this?

---

<div class="post-metadata">

**Author:** ![jalves](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/jalves/32/1020_2.png) [@jalves](https://forum.langchain.com/u/jalves)\
**Post date:** [September 19, 2025, 12:12am UTC](https://forum.langchain.com/t/the-best-way-in-langgraph-to-control-flow-after-retries-exhausted/1574/2 "2025-09-19T00:12:31Z")

</div>

> [@utkarsh1205](#):
>
> What’s the best to control the flow of the graph when a retriable node exhausts all the retries.
> 
> We can apply Retry policies to nodes in langgraph like so -  
> builder.add\_node( “node\_name”, node\_function, retry\_policy=RetryPolicy(), )
> 
> Now, if I want to redirect the flow to another node when all retries are exhausted (instead of raising that error), I would not use the above retry\_policy parameter. Instead I would create my own retry wrapper, wrap it around my method I am trying to execute and call that method in my langgraph node. Inside the langgraph node I handle the retry exhausted error.
> 
> Is there a simpler pattern available in LangGraph’s Graph API to help me do this

I don’t think LangGraph provide a simpler or declarative pattern in the Graph API to automatically redirect flow on retry exhaustion, your approach looks good based on the existent resources.

---

<div class="post-metadata">

**Author:** ![pawel-twardziak](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/pawel-twardziak/32/960_2.png) [@pawel-twardziak](https://forum.langchain.com/u/pawel-twardziak)\
**Post date:** [September 23, 2025, 4:35pm UTC](https://forum.langchain.com/t/the-best-way-in-langgraph-to-control-flow-after-retries-exhausted/1574/3 "2025-09-23T16:35:00Z")

</div>

Hi @utkarsh1205

## IMHO, what do you think about these examples?

### Control flow when retries are exhausted in LangGraph

**Short answer:** `RetryPolicy` has no built‑in “on exhaustion, go to X” hook. When a node still fails after all retries, it raises. To redirect flow instead of raising, handle it inside your node and return a `Command` with `goto` (or set a flag and route via a conditional edge).

References: [Graph API – Retry policies](https://langchain-ai.github.io/langgraph/how-tos/graph-api/#add-retry-policies), [Command](https://langchain-ai.github.io/langgraph/reference/types/#langgraph.types.Command), [Conditional edges](https://langchain-ai.github.io/langgraph/how-tos/graph-api/#conditional-branching).

### Option 1 (recommended): Manual retry in node + Command.goto fallback

```python
from time import sleep
from langgraph.types import Command

MAX_ATTEMPTS = 3

def work(state):
    for i in range(MAX_ATTEMPTS):
        try:
            data = call_external_api()
            return {"data": data}
        except TransientError as e:
            if i < MAX_ATTEMPTS - 1:
                sleep(2 ** i) # backoff
            else:
                # retries exhausted -> hop to fallback node
                return Command(update={"error": str(e)}, goto="fallback")

def fallback(state):
    ...

# builder wiring
# builder.add_node("work", work)
# builder.add_node("fallback", fallback)
# builder.add_edge(START, "work")
# builder.add_edge("fallback", END)

```

This keeps failure local, updates state, and explicitly routes to `fallback` without throwing.

### Option 2: Catch, set a flag, then use conditional edges

```python
def work(state):
    try:
        return {"data": call_external_api(), "failed": False}
    except Exception as e:
        return {"failed": True, "error": str(e)}

def route(state) -> str:
    return "fallback" if state.get("failed") else "next"

# builder.add_node("work", work)
# builder.add_node("next", next_node)
# builder.add_node("fallback", fallback)
# builder.add_edge(START, "work")
# builder.add_conditional_edges("work", route)

```

### Can I keep `retry_policy` and still redirect?

You can use `retry_policy` for transient failures, but once it exhausts it raises. There’s no on‑exhaust callback. If you need redirect-on-exhaustion, implement the retry loop inside the node and return `Command.goto` (Option 1) or use a conditional edge (Option 2).

### Functional API note

With `@task(retry_policy=...)`, exhaustion also raises. Redirect by catching in your `@entrypoint` or by doing manual retries inside the task and returning a value that drives subsequent control flow.
