Skip to content

invalid_tool_call blocks still reach groq and mistralai during v1 conversion #40931

Description

@quotentiroler

#39803 and #39805 filtered invalid_tool_call out of v1 conversion for anthropic and fireworks, because both providers reject the block when partial or malformed tool-call history is replayed. langchain_openai.chat_models._compat has the same filter.

langchain_groq and langchain_mistralai have the same converter shape and no filter, so the block is passed through to the provider.

from langchain_core.messages import AIMessage

blocks = [
    {"type": "text", "text": "hello"},
    {"type": "invalid_tool_call", "name": "get_weather", "args": "{bad json",
     "id": "call_1", "error": "Malformed args."},
]
msg = AIMessage(content=blocks, invalid_tool_calls=[
    {"name": "get_weather", "args": "{bad json", "id": "call_1",
     "error": "Malformed args.", "type": "invalid_tool_call"}])

from langchain_groq._compat import _convert_from_v1_to_groq
from langchain_mistralai._compat import _convert_from_v1_to_mistral
from langchain_openai.chat_models._compat import _convert_from_v1_to_chat_completions
from langchain_anthropic._compat import _convert_from_v1_to_anthropic
openai    (has filter) -> ['text']
anthropic (has filter) -> ['text']
groq      (no filter)  -> ['text', 'invalid_tool_call']
mistralai (no filter)  -> ['text', 'invalid_tool_call']

Both converters end with a catch-all that re-emits anything unrecognised:

else:
    new_content.append(block)

so the block survives for the same reason it did in fireworks before #39805, where the fix was adding "invalid_tool_call" to the tuple of skipped types.

langchain_ollama has no such catch-all and drops unrecognised blocks, so it is not affected.

Versions: langchain-core 1.6.6, langchain-groq 1.1.3, langchain-mistralai 1.1.6, langchain-openai 1.6.6, langchain-anthropic 1.7.5, Python 3.14.2.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions