langchain-ai/langchain · error · TypeError
Expected a callable type for `func`.Instead got an unsupport
Error message
Expected a callable type for `func`.Instead got an unsupported type: {type(func)} What it means
`RunnableLambda.__init__` checks `callable(func)` and raises `TypeError` if the value is not callable. The message is marked `unreachable` by the type checker because the static signature promises a callable, but at runtime Python allows anything to be passed. Typical causes are passing a called result instead of the function, or `None` from a failed factory.
Source
Thrown at libs/core/langchain_core/runnables/base.py:4935
if is_async_callable(func) or is_async_generator(func):
if afunc is not None:
msg = (
"Func was provided as a coroutine function, but afunc was "
"also provided. If providing both, func should be a regular "
"function to avoid ambiguity."
)
raise TypeError(msg)
self.afunc = func
func_for_name = func
elif callable(func):
self.func = cast("Callable[[Input], Output]", func)
func_for_name = func
else:
msg = ( # type: ignore[unreachable]
"Expected a callable type for `func`."
f"Instead got an unsupported type: {type(func)}"
)
raise TypeError(msg)
try:
if name is not None:
self.name = name
elif func_for_name.__name__ != "<lambda>":
self.name = func_for_name.__name__
except AttributeError:
pass
self._repr: str | None = None
@property
@override
def InputType(self) -> Any:
"""The type of the input to this `Runnable`."""
func = getattr(self, "func", None) or self.afunc
try:
params = inspect.signature(func).parametersView on GitHub (pinned to e32fa9a52e)
Solutions
- Pass the function object, not its result: `RunnableLambda(my_fn)`, not `RunnableLambda(my_fn())`.
- Default `None` to a no-op or raise a clear error at the call site: `assert func is not None`.
- Validate with `callable(func)` before constructing when the callable comes from external config.
- If you intended to bind arguments, use `functools.partial`.
Example fix
// before runnable = RunnableLambda(extract_text(raw_doc)) # called -> returns str // after runnable = RunnableLambda(extract_text) # function object // or bind args: runnable = RunnableLambda(functools.partial(extract_text, fmt='markdown'))
Defensive patterns
Strategy: type-guard
Validate before calling
assert func is not None and callable(func), f'func must be callable, got {type(func)}' Type guard
def is_callable_not_none(fn) -> bool:
return fn is not None and callable(fn) Try / catch
try:
r = RunnableLambda(func)
except TypeError as e:
if 'Expected a callable type' in str(e):
raise ValueError('Did you pass fn() instead of fn?') from e
raise Prevention
- Pass function objects, never their results.
- Use functools.partial to bind arguments instead of pre-calling.
- Assert callable(func) when func comes from config or registry lookups.
When it happens
Trigger: `RunnableLambda(my_fn())` (calls the function instead of passing it); `RunnableLambda(None)` when an optional loader returned `None`; `RunnableLambda('prompt_template')` (a string); passing a class instance without `__call__`.
Common situations: Missing parentheses confusion — passing `fn(x)` result where `fn` was expected; conditionally constructed callables (`func = maybe_get_handler() or None`); data-driven configs mapping names to functions where a lookup failed.
Related errors
- Func was provided as a coroutine function, but afunc was als
- Cannot invoke a coroutine function synchronously.Use `ainvok
- Cannot stream a coroutine function synchronously.Use `astrea
- RunnableSequence must have at least {_RUNNABLE_SEQUENCE_MIN_
- Expected a generator function type for `transform`.Instead g
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/82aaec9ae769c30d.
Report an issue: GitHub.