TypeError
builtins.TypeError
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
@traceable
File "/usr/local/lib/python3.10/site-packages/langsmith/decorators.py", line 58, in traceable
def wrapper(*args, **kwargs):
TypeError: 'coroutine' object is not callable Why it happens
The LangSmith traceable decorator is designed for synchronous functions by default. When applied to async functions without using an async-compatible wrapper, it attempts to call the coroutine object directly, causing a TypeError because coroutines must be awaited.
Detection
Monitor for TypeError exceptions mentioning 'coroutine object is not callable' in logs when using LangSmith decorators on async functions, and add logging around decorated async functions to catch this early.
Causes & fixes
Applying the synchronous traceable decorator to an async function without async support
Use the async-compatible version of the traceable decorator or wrap the decorator logic inside an async wrapper function that awaits the coroutine.
Forgetting to await the decorated async function inside the decorator implementation
Modify the decorator to await the async function call inside the wrapper to properly handle coroutine execution.
Using an outdated LangSmith version that lacks async decorator support
Upgrade LangSmith to the latest version that includes async-compatible traceable decorators.
Code: broken vs fixed
from langsmith import traceable
@traceable
async def fetch_data():
return await some_async_call()
result = fetch_data() # TypeError: 'coroutine' object is not callable import os
from langsmith import traceable_async
os.environ['LANGSMITH_API_KEY'] = os.getenv('LANGSMITH_API_KEY') # Ensure API key is set
@traceable_async # Changed to async-compatible decorator
async def fetch_data():
return await some_async_call()
import asyncio
result = asyncio.run(fetch_data()) # Works correctly with async decorator
print(result) Workaround
Wrap the async function call inside a synchronous wrapper that runs the coroutine with asyncio.run or loop.run_until_complete, allowing use of the synchronous decorator temporarily.
Prevention
Always use async-compatible decorators for async functions and verify decorator support for async before applying; prefer LangSmith's official async traceable decorators to avoid coroutine call errors.