Non-informative / Confusing error message when invoking async graph nodes using sync calls (TypeError: None is not a callable object) #97

Closed
opened 2026-02-20 17:25:49 -05:00 by yindo · 1 comment
Owner

Originally created by @vreyespue on GitHub (May 29, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

from langgraph.graph import StateGraph
from langchain_google_vertexai import ChatVertexAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from typing import TypedDict


class FlowState(TypedDict):
    original_utterance: str
    pirate_utterance: str


llm = ChatVertexAI(
    model_name="gemini-1.5-flash-001",
    project="rd-bdlab-9c32",
    location="europe-west1",
    temperature=0.0,
    max_retries=0,
)

single_message_template = """Given the following utterance, rewrite it as if you were a pirate. Utterance: {original_utterance}"""
prompt_template = ChatPromptTemplate.from_messages([("human", single_message_template)])

rewriter = prompt_template | llm | StrOutputParser()


async def rewriter_node(state: FlowState):
    original_utterance = state["original_utterance"]
    pirate_utterance = await rewriter.ainvoke(state)  # type: ignore
    return {
        "original_utterance": original_utterance,
        "pirate_utterance": pirate_utterance,
    }


workflow = StateGraph(FlowState)

workflow.add_node("rewriter", rewriter_node)
workflow.set_entry_point("rewriter")
workflow.set_finish_point("rewriter")

graph = workflow.compile()

result = graph.invoke(
    {
        "original_utterance": "The weather is nice today.",
    },
    debug=True,
)

Error Message and Stack Trace (if applicable)

[0:tasks] Starting step 0 with 1 task:
- __start__ -> {'original_utterance': 'The weather is nice today.'}
[0:writes] Finished step 0 with writes to 1 channel:
- original_utterance -> 'The weather is nice today.'
[0:checkpoint] State at the end of step 0:
{'original_utterance': 'The weather is nice today.'}
[1:tasks] Starting step 1 with 1 task:
- rewriter -> {'original_utterance': 'The weather is nice today.', 'pirate_utterance': None}
[1:writes] Finished step 1 with writes to 2 channels:
- original_utterance -> 'The weather is nice today.'
- pirate_utterance -> ("Ahoy, matey! The sun be shinin' like a doubloon, and the wind be blowin' "
 "fair. A fine day for sailin', I'd say! \n")
[1:checkpoint] State at the end of step 1:
{'original_utterance': 'The weather is nice today.',
 'pirate_utterance': "Ahoy, matey! The sun be shinin' like a doubloon, and the "
                     "wind be blowin' fair. A fine day for sailin', I'd "
                     'say! \n'}
langserver-py3.12➜  ~/git/rewe-digital-ecom/pi-ai-shop-assistant/langserver git:(feature/NOTICKET/new-flow) ✗ poetry run python graph/example.py
[0:tasks] Starting step 0 with 1 task:
- __start__ -> {'original_utterance': 'The weather is nice today.'}
[0:writes] Finished step 0 with writes to 1 channel:
- original_utterance -> 'The weather is nice today.'
[0:checkpoint] State at the end of step 0:
{'original_utterance': 'The weather is nice today.'}
[1:tasks] Starting step 1 with 1 task:
- rewriter -> {'original_utterance': 'The weather is nice today.', 'pirate_utterance': None}
Traceback (most recent call last):
  File "example.py", line 44, in <module>
    result = graph.invoke(
             ^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 1333, in invoke
    for chunk in self.stream(
  File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 876, in stream
    _panic_or_proceed(done, inflight, step)
  File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 1422, in _panic_or_proceed
    raise exc
  File "lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/langgraph/pregel/retry.py", line 66, in run_with_retry
    task.proc.invoke(task.input, task.config)
  File "lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2393, in invoke
    input = step.invoke(
            ^^^^^^^^^^^^
  File "lib/python3.12/site-packages/langgraph/utils.py", line 86, in invoke
    if accepts_config(self.func)
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/site-packages/langchain_core/runnables/utils.py", line 86, in accepts_config
    return signature(callable).parameters.get("config") is not None
           ^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/inspect.py", line 3310, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/inspect.py", line 3054, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.12/inspect.py", line 2491, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))

TypeError: None is not a callable object

Description

  • I am trying to run a graph containing async nodes using a normal sync invoke call
  • I expect to get a clear and informative error stating that this is not supported
  • Instead, I get a non-informative / confusing error from langchain_core/runnables/utils.py (TypeError: None is not a callable object)
  • As a consequence, the code is not trivial to debug.

System Info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
> Python Version:  3.12.3 (main, May 23 2024, 10:10:53) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information
-------------------
> langchain_core: 0.2.1
> langchain: 0.2.1
> langsmith: 0.1.57
> langchain_chroma: 0.1.1
> langchain_google_vertexai: 1.0.4
> langchain_text_splitters: 0.2.0
> langgraph: 0.0.55

Packages not installed (Not Necessarily a Problem)
--------------------------------------------------
The following packages were not found:

> langserve
Originally created by @vreyespue on GitHub (May 29, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangChain rather than my code. ### Example Code ``` from langgraph.graph import StateGraph from langchain_google_vertexai import ChatVertexAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser from typing import TypedDict class FlowState(TypedDict): original_utterance: str pirate_utterance: str llm = ChatVertexAI( model_name="gemini-1.5-flash-001", project="rd-bdlab-9c32", location="europe-west1", temperature=0.0, max_retries=0, ) single_message_template = """Given the following utterance, rewrite it as if you were a pirate. Utterance: {original_utterance}""" prompt_template = ChatPromptTemplate.from_messages([("human", single_message_template)]) rewriter = prompt_template | llm | StrOutputParser() async def rewriter_node(state: FlowState): original_utterance = state["original_utterance"] pirate_utterance = await rewriter.ainvoke(state) # type: ignore return { "original_utterance": original_utterance, "pirate_utterance": pirate_utterance, } workflow = StateGraph(FlowState) workflow.add_node("rewriter", rewriter_node) workflow.set_entry_point("rewriter") workflow.set_finish_point("rewriter") graph = workflow.compile() result = graph.invoke( { "original_utterance": "The weather is nice today.", }, debug=True, ) ``` ### Error Message and Stack Trace (if applicable) ``` [0:tasks] Starting step 0 with 1 task: - __start__ -> {'original_utterance': 'The weather is nice today.'} [0:writes] Finished step 0 with writes to 1 channel: - original_utterance -> 'The weather is nice today.' [0:checkpoint] State at the end of step 0: {'original_utterance': 'The weather is nice today.'} [1:tasks] Starting step 1 with 1 task: - rewriter -> {'original_utterance': 'The weather is nice today.', 'pirate_utterance': None} [1:writes] Finished step 1 with writes to 2 channels: - original_utterance -> 'The weather is nice today.' - pirate_utterance -> ("Ahoy, matey! The sun be shinin' like a doubloon, and the wind be blowin' " "fair. A fine day for sailin', I'd say! \n") [1:checkpoint] State at the end of step 1: {'original_utterance': 'The weather is nice today.', 'pirate_utterance': "Ahoy, matey! The sun be shinin' like a doubloon, and the " "wind be blowin' fair. A fine day for sailin', I'd " 'say! \n'} langserver-py3.12➜ ~/git/rewe-digital-ecom/pi-ai-shop-assistant/langserver git:(feature/NOTICKET/new-flow) ✗ poetry run python graph/example.py [0:tasks] Starting step 0 with 1 task: - __start__ -> {'original_utterance': 'The weather is nice today.'} [0:writes] Finished step 0 with writes to 1 channel: - original_utterance -> 'The weather is nice today.' [0:checkpoint] State at the end of step 0: {'original_utterance': 'The weather is nice today.'} [1:tasks] Starting step 1 with 1 task: - rewriter -> {'original_utterance': 'The weather is nice today.', 'pirate_utterance': None} Traceback (most recent call last): File "example.py", line 44, in <module> result = graph.invoke( ^^^^^^^^^^^^^ File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 1333, in invoke for chunk in self.stream( File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 876, in stream _panic_or_proceed(done, inflight, step) File "lib/python3.12/site-packages/langgraph/pregel/__init__.py", line 1422, in _panic_or_proceed raise exc File "lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "lib/python3.12/site-packages/langgraph/pregel/retry.py", line 66, in run_with_retry task.proc.invoke(task.input, task.config) File "lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2393, in invoke input = step.invoke( ^^^^^^^^^^^^ File "lib/python3.12/site-packages/langgraph/utils.py", line 86, in invoke if accepts_config(self.func) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "lib/python3.12/site-packages/langchain_core/runnables/utils.py", line 86, in accepts_config return signature(callable).parameters.get("config") is not None ^^^^^^^^^^^^^^^^^^^ File "lib/python3.12/inspect.py", line 3310, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "lib/python3.12/inspect.py", line 3054, in from_callable return _signature_from_callable(obj, sigcls=cls, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "lib/python3.12/inspect.py", line 2491, in _signature_from_callable raise TypeError('{!r} is not a callable object'.format(obj)) TypeError: None is not a callable object ``` ### Description * I am trying to run a graph containing async nodes using a normal sync `invoke` call * I expect to get a clear and informative error stating that this is not supported * Instead, I get a non-informative / confusing error from `langchain_core/runnables/utils.py` (TypeError: None is not a callable object) * As a consequence, the code is not trivial to debug. ### System Info ``` System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 > Python Version: 3.12.3 (main, May 23 2024, 10:10:53) [Clang 15.0.0 (clang-1500.3.9.4)] Package Information ------------------- > langchain_core: 0.2.1 > langchain: 0.2.1 > langsmith: 0.1.57 > langchain_chroma: 0.1.1 > langchain_google_vertexai: 1.0.4 > langchain_text_splitters: 0.2.0 > langgraph: 0.0.55 Packages not installed (Not Necessarily a Problem) -------------------------------------------------- The following packages were not found: > langserve ```
yindo closed this issue 2026-02-20 17:25:52 -05:00
Author
Owner

@vreyespue commented on GitHub (May 29, 2024):

@hinthornw @nfcampos many thanks! 😎 🚀

@vreyespue commented on GitHub (May 29, 2024): @hinthornw @nfcampos many thanks! 😎 🚀
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#97