langchain-ai
langchain
BlogDocsChangelog

xai[patch]: Fix 400 error for AIMessages with tool_calls but no content

#34229
Comparing
arrdel:fix-chatxai-empty-content-34140
(
35c1c1f
) with
master
(
80c3970
)
CodSpeed Performance Gauge
0%
Untouched
1
Skipped
33

Benchmarks

Skipped (33)

test_create_chat_prompt_init_time
libs/partners/prompty/tests/unit_tests/test_standard.py
Skipped
311.9 µs*
test_nomic_embeddings_init_time
libs/partners/nomic/tests/unit_tests/test_standard.py
Skipped
1.5 ms*
test_init_time
libs/partners/deepseek/tests/unit_tests/test_chat_models.py::TestChatDeepSeekUnit
Skipped
1.6 s*
test_exa_retriever_init_time
libs/partners/exa/tests/unit_tests/test_standard.py
Skipped
319.1 µs*
test_init_time
libs/partners/fireworks/tests/unit_tests/test_standard.py::TestFireworksStandard
Skipped
6.6 s*
test_init_time
libs/partners/mistralai/tests/unit_tests/test_standard.py::TestMistralStandard
Skipped
9.2 ms*
test_init_time
libs/partners/perplexity/tests/unit_tests/test_chat_models_standard.py::TestPerplexityStandard
Skipped
834.5 ms*
test_chroma_init_time
libs/partners/chroma/tests/unit_tests/test_standard.py
Skipped
57.2 ms*
test_init_time
libs/partners/ollama/tests/unit_tests/test_chat_models.py::TestChatOllama
Skipped
1.6 s*
test_init_time
libs/partners/groq/tests/unit_tests/test_standard.py::TestGroqStandard
Skipped
1.6 s*
test_qdrant_vectorstore_init_time
libs/partners/qdrant/tests/unit_tests/test_standard.py
Skipped
223.9 ms*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIStandard
Skipped
1.1 s*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_responses_standard.py::TestOpenAIResponses
Skipped
12.3 ms*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_azure_standard.py::TestOpenAIStandard
Skipped
1.7 s*
test_init_time
libs/partners/openai/tests/unit_tests/chat_models/test_base_standard.py::TestOpenAIStandard
Skipped
12.2 ms*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_base_standard.py::TestOpenAIStandard
Skipped
1.2 s*
test_stream_time
libs/partners/openai/tests/integration_tests/chat_models/test_responses_standard.py::TestOpenAIResponses
Skipped
856.8 ms*
test_stream_time
libs/partners/anthropic/tests/integration_tests/test_standard.py::TestAnthropicStandard
Skipped
34.7 ms*
test_init_time
libs/partners/anthropic/tests/unit_tests/test_standard.py::TestAnthropicStandard
Skipped
811.9 µs*
test_init_time_with_client
libs/partners/anthropic/tests/unit_tests/test_standard.py
Skipped
2.3 ms*
test_import_time[Document]
libs/core/tests/benchmarks/test_imports.py
Skipped
185.5 ms*
test_import_time[InMemoryRateLimiter]
libs/core/tests/benchmarks/test_imports.py
Skipped
173.3 ms*
test_import_time[RunnableLambda]
libs/core/tests/benchmarks/test_imports.py
Skipped
490.6 ms*
test_import_time[InMemoryVectorStore]
libs/core/tests/benchmarks/test_imports.py
Skipped
610 ms*
test_import_time[ChatPromptTemplate]
libs/core/tests/benchmarks/test_imports.py
Skipped
594.1 ms*
test_import_time[BaseChatModel]
libs/core/tests/benchmarks/test_imports.py
Skipped
523.1 ms*
test_async_callbacks_in_sync
libs/core/tests/benchmarks/test_async_callbacks.py
Skipped
24.2 ms*
test_import_time[Runnable]
libs/core/tests/benchmarks/test_imports.py
Skipped
488.6 ms*
test_import_time[tool]
libs/core/tests/benchmarks/test_imports.py
Skipped
507.7 ms*
test_import_time[LangChainTracer]
libs/core/tests/benchmarks/test_imports.py
Skipped
435.2 ms*
test_import_time[HumanMessage]
libs/core/tests/benchmarks/test_imports.py
Skipped
263 ms*
test_import_time[PydanticOutputParser]
libs/core/tests/benchmarks/test_imports.py
Skipped
528.6 ms*
test_import_time[CallbackManager]
libs/core/tests/benchmarks/test_imports.py
Skipped
455.9 ms*

Passed

test_init_time
libs/partners/xai/tests/unit_tests/test_chat_models_standard.py::TestXAIStandard
CodSpeed Performance Gauge
0%
3.3 s*3.3 s

Commits

Click on a commit to change the comparison range
Base
master
80c3970
+0.01%
Fix ChatXAI: Ensure AIMessages with tool_calls have empty content instead of None xAI's API is stricter than OpenAI's and requires all messages to have at least an empty content field. When using LangGraph agents with tool calling, AIMessages can have tool_calls but no content, which causes xAI to return a 400 error: 'Invalid request content: Each message must have at least one content element.' This fix overrides the message conversion logic in ChatXAI to ensure that AIMessages with tool_calls or function_call always have at least an empty string for content, rather than None (which is acceptable for OpenAI but not xAI). Changes: - Added _convert_message_to_dict_xai() function that wraps the OpenAI converter and ensures content is never None for AIMessages with tool calls - Overrode _get_request_payload() to use the xAI-specific converter - Added necessary imports from langchain_openai.chat_models.base Fixes #34140
35c1c1f
20 hours ago
by arrdel
© 2025 CodSpeed Technology
Home Terms Privacy Docs