You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using LangGraph's pre-built ReAct agentcreate_react_agent() along with ChatVertexAI. Occasionally I was seeing 400 responses from VertexAI:
Retrying langchain_google_vertexai.chat_models._completion_with_retry.<locals>._completion_with_retry_inner in 4.0 seconds as it raised InvalidArgument: 400 Unable to submit request because it must include at least one parts field, which describes the prompt input.
Stacktrace
Traceback (mostrecentcalllast):
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/google/api_core/grpc_helpers.py", line76, inerror_remapped_callablereturncallable_(*args, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_interceptor.py", line277, in__call__response, ignored_call=self._with_call(
~~~~~~~~~~~~~~~^request,
^^^^^^^^
...<4lines>...
compression=compression,
^^^^^^^^^^^^^^^^^^^^^^^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_interceptor.py", line332, in_with_callreturncall.result(), call~~~~~~~~~~~^^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_channel.py", line440, inresultraiseselfFile"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_interceptor.py", line315, incontinuationresponse, call=self._thunk(new_method).with_call(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^request,
^^^^^^^^
...<4lines>...
compression=new_compression,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_channel.py", line1198, inwith_callreturn_end_unary_response_blocking(state, call, True, None)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/grpc/_channel.py", line1006, in_end_unary_response_blockingraise_InactiveRpcError(state) # pytype: disable=not-instantiable^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^grpc._channel._InactiveRpcError: <_InactiveRpcErrorofRPCthatterminatedwith:
status=StatusCode.INVALID_ARGUMENTdetails="Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini"debug_error_string="UNKNOWN:Error received from peer ipv4:142.251.16.95:443 {grpc_message:"Unabletosubmitrequestbecauseitmustincludeatleastonepartsfield, whichdescribesthepromptinput. Learnmore: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini", grpc_status:3, created_time:"2025-04-10T20:45:21.468704714+00:00"}">Theaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line587, inuse_spanyieldspanFile"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line1105, instart_as_current_spanyieldspanFile"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/src/langgraph_chatbot_demo/langchain_history.py", line215, in<module>res=app.invoke({"messages": [message]}, config=config)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line2669, ininvokeforchunkinself.stream(
~~~~~~~~~~~^input,
^^^^^^
...<6lines>...
**kwargs,
^^^^^^^^^
):
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line2323, instreamfor_inrunner.tick(
~~~~~~~~~~~^loop.tasks.values(),
^^^^^^^^^^^^^^^^^^^^
...<2lines>...
get_waiter=get_waiter,
^^^^^^^^^^^^^^^^^^^^^^
):
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/pregel/runner.py", line146, intickrun_with_retry(
~~~~~~~~~~~~~~^t,
^^
...<11lines>...
},
^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/pregel/retry.py", line40, inrun_with_retryreturntask.proc.invoke(task.input, config)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/utils/runnable.py", line600, ininvokeinput=step.invoke(input, config, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/utils/runnable.py", line357, ininvokeret=context.run(self.func, *args, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langgraph/prebuilt/chat_agent_executor.py", line686, incall_modelresponse=cast(AIMessage, model_runnable.invoke(state, config))
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/runnables/base.py", line3025, ininvokeinput=context.run(step.invoke, input, config)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/runnables/base.py", line5358, ininvokereturnself.bound.invoke(
~~~~~~~~~~~~~~~~~^input,
^^^^^^self._merge_configs(config),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^**{**self.kwargs, **kwargs},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py", line307, ininvokeself.generate_prompt(
~~~~~~~~~~~~~~~~~~~~^
[self._convert_input(input)],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<6lines>...
**kwargs,
^^^^^^^^^
).generations[0][0],
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py", line843, ingenerate_promptreturnself.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py", line683, ingenerateself._generate_with_cache(
~~~~~~~~~~~~~~~~~~~~~~~~~^m,
^^
...<2lines>...
**kwargs,
^^^^^^^^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py", line908, in_generate_with_cacheresult=self._generate(
messages, stop=stop, run_manager=run_manager, **kwargs
)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_google_vertexai/chat_models.py", line1310, in_generatereturnself._generate_gemini(
~~~~~~~~~~~~~~~~~~~~~^messages=messages,
^^^^^^^^^^^^^^^^^^
...<3lines>...
**kwargs,
^^^^^^^^^
)
^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_google_vertexai/chat_models.py", line1546, in_generate_geminiresponse=_completion_with_retry(
self.prediction_client.generate_content,
...<5lines>...
**kwargs,
)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_google_vertexai/chat_models.py", line636, in_completion_with_retryreturn_completion_with_retry_inner(
generation_method,
**params,
)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line336, inwrapped_freturncopy(f, *args, **kw)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line475, in__call__do=self.iter(retry_state=retry_state)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line376, initerresult=action(retry_state)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line418, inexc_checkraiseretry_exc.reraise()
~~~~~~~~~~~~~~~~~^^File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line185, inreraiseraiseself.last_attempt.result()
~~~~~~~~~~~~~~~~~~~~~~~~^^File"/usr/local/google/home/aaronabbott/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line449, inresultreturnself.__get_result()
~~~~~~~~~~~~~~~~~^^File"/usr/local/google/home/aaronabbott/.local/share/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line401, in__get_resultraiseself._exceptionFile"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/tenacity/__init__.py", line478, in__call__result=fn(*args, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/langchain_google_vertexai/chat_models.py", line629, in_completion_with_retry_innerreturngeneration_method(**kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/opentelemetry/instrumentation/vertexai/patch.py", line168, ingenerate_contentresponse=wrapped(*args, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py", line2396, ingenerate_contentresponse=rpc(
request,
...<2lines>...
metadata=metadata,
)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/google/api_core/gapic_v1/method.py", line131, in__call__returnwrapped_func(*args, **kwargs)
File"/usr/local/google/home/aaronabbott/repo/opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/.venv/lib/python3.13/site-packages/google/api_core/grpc_helpers.py", line78, inerror_remapped_callableraiseexceptions.from_grpc_error(exc) fromexcgoogle.api_core.exceptions.InvalidArgument: 400Unabletosubmitrequestbecauseitmustincludeatleastonepartsfield, whichdescribesthepromptinput. Learnmore: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini [detail: "[ORIGINAL ERROR] generic::invalid_argument: Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini [google.rpc.error_details_ext] { message: \"Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini\" } 525003295 { 1 { 1 { 1 { 1: \"blade:cloud.ai.nl.llm.proto.service.languagemodelservice-prod-us-central1\" 2: \"LanguageModelService\" 3: \"GenerateMultiModal\" } 2 { 1: 3 2: \"generic\" 3: \"Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini\" 5 { 1 { 2: 82012934 3 { 2: \"Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://c...(length 1195)"
]
Duringtaskwithname'agent'andid'e3877e3b-5f8b-c7c1-5e45-62f47f273458'
I debugged the problem and it happens If Gemini returns a blocked response (finishes with SAFETY reason) in an earlier interaction. LangGraph's checkpointer keeps a record of the blocked message which ChatVertexAI turns into an empty Content with no Parts in the RPC. Filtering out the blocked messages fixes the problem:
classPatchedChatVertexAI(ChatVertexAI):
def_prepare_request_gemini(
self, messages: list[BaseMessage], *args: Any, **kwargs: Any
) ->v1GenerateContentRequest|GenerateContentRequest:
# Filter out any blocked messages with no content which can appear if you have a blocked# message from finish_reason SAFETY:messages= [
messageformessageinmessagesifnotmessage.response_metadata.get("is_blocked", False)
]
returnsuper()._prepare_request_gemini(messages, *args, **kwargs)
I'm happy to submit a fix.
The text was updated successfully, but these errors were encountered:
I'm using LangGraph's pre-built ReAct agent
create_react_agent()
along with ChatVertexAI. Occasionally I was seeing 400 responses from VertexAI:Retrying langchain_google_vertexai.chat_models._completion_with_retry.<locals>._completion_with_retry_inner in 4.0 seconds as it raised InvalidArgument: 400 Unable to submit request because it must include at least one parts field, which describes the prompt input.
Stacktrace
I debugged the problem and it happens If Gemini returns a blocked response (finishes with
SAFETY
reason) in an earlier interaction. LangGraph's checkpointer keeps a record of the blocked message which ChatVertexAI turns into an emptyContent
with noPart
s in the RPC. Filtering out the blocked messages fixes the problem:I'm happy to submit a fix.
The text was updated successfully, but these errors were encountered: