{"record":{"id":"82aaec9ae769c30d","repo":"langchain-ai/langchain","slug":"expected-a-callable-type-for-func-instead-got-an","errorCode":null,"errorMessage":"Expected a callable type for `func`.Instead got an unsupported type: {type(func)}","messagePattern":"Expected a callable type for `func`\\.Instead got an unsupported type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/runnables/base.py","lineNumber":4935,"sourceCode":"        if is_async_callable(func) or is_async_generator(func):\n            if afunc is not None:\n                msg = (\n                    \"Func was provided as a coroutine function, but afunc was \"\n                    \"also provided. If providing both, func should be a regular \"\n                    \"function to avoid ambiguity.\"\n                )\n                raise TypeError(msg)\n            self.afunc = func\n            func_for_name = func\n        elif callable(func):\n            self.func = cast(\"Callable[[Input], Output]\", func)\n            func_for_name = func\n        else:\n            msg = (  # type: ignore[unreachable]\n                \"Expected a callable type for `func`.\"\n                f\"Instead got an unsupported type: {type(func)}\"\n            )\n            raise TypeError(msg)\n\n        try:\n            if name is not None:\n                self.name = name\n            elif func_for_name.__name__ != \"<lambda>\":\n                self.name = func_for_name.__name__\n        except AttributeError:\n            pass\n\n        self._repr: str | None = None\n\n    @property\n    @override\n    def InputType(self) -> Any:\n        \"\"\"The type of the input to this `Runnable`.\"\"\"\n        func = getattr(self, \"func\", None) or self.afunc\n        try:\n            params = inspect.signature(func).parameters","sourceCodeStart":4917,"sourceCodeEnd":4953,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/runnables/base.py#L4917-L4953","documentation":"`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.","triggerScenarios":"`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__`.","commonSituations":"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.","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`."],"exampleFix":"// before\nrunnable = RunnableLambda(extract_text(raw_doc))  # called -> returns str\n\n// after\nrunnable = RunnableLambda(extract_text)  # function object\n// or bind args:\nrunnable = RunnableLambda(functools.partial(extract_text, fmt='markdown'))","handlingStrategy":"type-guard","validationCode":"assert func is not None and callable(func), f'func must be callable, got {type(func)}'","typeGuard":"def is_callable_not_none(fn) -> bool:\n    return fn is not None and callable(fn)","tryCatchPattern":"try:\n    r = RunnableLambda(func)\nexcept TypeError as e:\n    if 'Expected a callable type' in str(e):\n        raise ValueError('Did you pass fn() instead of fn?') from e\n    raise","preventionTips":["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."],"tags":["runnable","runnable-lambda","typeerror","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}