High severity intermediate · Fix: 5-10 min

TypeError

TypeError: object NoneType can't be used in 'await' expression

What this error means
Langfuse's observe decorator raises a TypeError when used on async functions without proper async support, causing await failures.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    result = await observed_async_function()
  File "/usr/local/lib/python3.10/site-packages/langfuse/decorators.py", line 58, in wrapper
    response = await func(*args, **kwargs)  # TypeError: object NoneType can't be used in 'await' expression
TypeError: object NoneType can't be used in 'await' expression
QUICK FIX
Replace the observe decorator with its async-compatible version or modify the decorator to support async functions by using async def and await internally.

Why it happens

The Langfuse observe decorator is designed for synchronous functions by default. When applied to async functions without using the async-compatible decorator variant, it returns None instead of a coroutine, causing a TypeError when awaited.

Detection

Monitor for TypeError exceptions mentioning 'NoneType' in await expressions in logs when using Langfuse observe on async functions.

Causes & fixes

1

Using Langfuse's synchronous observe decorator on an async function

✓ Fix

Use the async-compatible observe decorator variant or ensure the decorator supports async functions by awaiting the wrapped coroutine properly.

2

Decorator wrapper function missing async keyword for async functions

✓ Fix

Define the decorator wrapper as async def and await the inner async function call.

3

Forgetting to return the awaited result inside the async decorator wrapper

✓ Fix

Add a return statement before awaiting the wrapped async function to propagate the result.

Code: broken vs fixed

Broken - triggers the error
python
from langfuse import observe

@observe  # This decorator is synchronous
async def fetch_data():
    return await some_async_call()

result = await fetch_data()  # TypeError occurs here
Fixed - works correctly
python
import os
from langfuse import observe_async

os.environ['LANGFUSE_API_KEY'] = os.environ.get('OPENAI_API_KEY', 'your_api_key_here')  # Use env var for API key

@observe_async  # Use async-compatible decorator
async def fetch_data():
    return await some_async_call()

import asyncio
result = asyncio.run(fetch_data())  # Works without TypeError
print(result)
Changed to use observe_async decorator that supports async functions by awaiting the wrapped coroutine and returning its result.

Workaround

Wrap the async function call in a try/except block catching TypeError, then call the original async function without the decorator as a fallback.

Prevention

Always use decorators explicitly designed for async functions when decorating async code, or implement decorators with async support to avoid await-related TypeErrors.

Python 3.9+ · langfuse >=0.5.0 · tested on 0.7.2
Verified 2026-04
Verify ↗

Community Notes

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