High severity intermediate · Fix: 2-5 min

TypeError

TypeError: Edge condition function must return a boolean or awaitable resolving to boolean

What this error means
LangGraph edge condition functions must return a boolean or awaitable resolving to boolean; returning other types causes this TypeError.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    graph.run()
  File "langgraph/core.py", line 128, in run
    if not await edge.condition():
TypeError: object of type 'NoneType' cannot be used in boolean context
QUICK FIX
Ensure all edge condition functions explicitly return a boolean or an awaitable resolving to boolean.

Why it happens

LangGraph expects edge condition functions to return a boolean value or an awaitable resolving to boolean. If the function returns None or any non-boolean type, the framework cannot evaluate the condition, causing a TypeError. This often happens when the function lacks an explicit return or returns an incompatible type.

Detection

Add type assertions or logging inside edge condition functions to verify they return booleans or awaitables resolving to booleans before runtime evaluation.

Causes & fixes

1

Edge condition function lacks an explicit return statement, returning None implicitly.

✓ Fix

Add an explicit return statement that returns a boolean value (True or False) in the edge condition function.

2

Edge condition function returns a non-boolean type such as a string or integer.

✓ Fix

Modify the function to return a boolean value or an awaitable resolving to boolean, ensuring correct type.

3

Edge condition function is asynchronous but does not return an awaitable (missing async keyword or missing return).

✓ Fix

Define the function with async def and ensure it returns an awaitable resolving to a boolean.

Code: broken vs fixed

Broken - triggers the error
python
def edge_condition():
    print("Checking condition")
    # Missing return statement causes None to be returned

# This triggers TypeError when LangGraph evaluates the edge condition
graph.add_edge(condition=edge_condition)  # Error here
Fixed - works correctly
python
import os

os.environ['LANGGRAPH_API_KEY'] = os.environ.get('LANGGRAPH_API_KEY', '')  # Use environment variable for keys

def edge_condition():
    print("Checking condition")
    return True  # Fixed: explicit boolean return

# Add edge with correct condition function
graph.add_edge(condition=edge_condition)
print("Edge condition function fixed and graph running")
Added explicit boolean return in edge condition function to satisfy LangGraph's requirement for boolean or awaitable return types.

Workaround

Wrap the edge condition function call in a try/except block to catch TypeError, then coerce or default the return value to a boolean before returning.

Prevention

Use static type checking or runtime type assertions on edge condition functions to guarantee they always return booleans or awaitables resolving to booleans before integrating with LangGraph.

Python 3.9+ · langgraph >=0.1.0 · tested on 0.4.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.