AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Invalid Tool Call Blocks Are Not Filtered In Langchain-Groq And Langchain-Mistralai V1 Converters

The v1 message converters in langchain-groq and langchain-mistralai do not filter out invalid_tool_call blocks, causing them to be passed to Groq and Mistral APIs. These providers may reject such blocks when replaying partial or malformed tool-call history, leading to runtime errors. Other providers (OpenAI, Anthropic, Fireworks) already filter these blocks.

highConfidence 92%LangchainAffected Vlangchain-Groq<=1.1.3Affected Vlangchain-Mistralai<=1.1.6

Origin Analysis

Both converters (in langchain_groq._compat._convert_from_v1_to_groq and langchain_mistralai._compat._convert_from_v1_to_mistral) have a catch-all else branch that appends any unrecognized block type to the output. They do not explicitly skip blocks of type 'invalid_tool_call', unlike the converters in langchain_openai, langchain_anthropic, and langchain_fireworks.
1. Install langchain-groq and langchain-mistralai. 2. Create an AIMessage with content blocks including a text block and an invalid_tool_call block, and an invalid_tool_calls list containing that invalid call. 3. Call the respective converter: _convert_from_v1_to_groq(blocks, 'groq') and _convert_from_v1_to_mistral(blocks, 'mistralai'). 4. Observe the output types: openai returns ['text'] while groq and mistralai return ['text', 'invalid_tool_call'].

Fixing Code Block

Edge Case Audit

This change may drop invalid tool call information from the message history sent to the provider. If the provider can handle such blocks without error in some cases, this could lead to loss of context. Before rolling out, ensure that any legitimate use of invalid_tool_call blocks (e.g., for debugging or introspection) is not impacted. The change is backward-compatible and low-risk; rollback is straightforward by reverting the added skip condition.

Ecosystem Topology