From 6215d14d514ef9e35aecb1c0337400d193a4c3b0 Mon Sep 17 00:00:00 2001 From: ioop Date: Thu, 20 Nov 2025 22:40:10 +0530 Subject: [PATCH] groq: allow kwargs in with_structured_output to override tool_choice Fixes #33995 Allow users to pass additional kwargs (like tool_choice) to with_structured_output() to avoid 400 errors when the model doesn't trigger a tool call. This aligns ChatGroq with ChatOpenAI behavior. Users can now override the default tool_choice: llm.with_structured_output(Schema, tool_choice="auto") --- libs/partners/groq/langchain_groq/chat_models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/partners/groq/langchain_groq/chat_models.py b/libs/partners/groq/langchain_groq/chat_models.py index 9fd02f230b216..b54491ce32e7a 100644 --- a/libs/partners/groq/langchain_groq/chat_models.py +++ b/libs/partners/groq/langchain_groq/chat_models.py @@ -1116,9 +1116,6 @@ class AnswerWithJustification(BaseModel): """ # noqa: E501 _ = kwargs.pop("strict", None) - if kwargs: - msg = f"Received unsupported arguments {kwargs}" - raise ValueError(msg) is_pydantic_schema = _is_pydantic_class(schema) if method == "function_calling": if schema is None: @@ -1136,6 +1133,7 @@ class AnswerWithJustification(BaseModel): "kwargs": {"method": "function_calling"}, "schema": formatted_tool, }, + **kwargs, ) if is_pydantic_schema: output_parser: OutputParserLike = PydanticToolsParser( @@ -1168,6 +1166,7 @@ class AnswerWithJustification(BaseModel): llm = self.bind( response_format=response_format, ls_structured_output_format=ls_format_info, + **kwargs, ) output_parser = ( PydanticOutputParser(pydantic_object=schema) # type: ignore[type-var, arg-type] @@ -1182,6 +1181,7 @@ class AnswerWithJustification(BaseModel): "kwargs": {"method": "json_mode"}, "schema": schema, }, + **kwargs, ) output_parser = ( PydanticOutputParser(pydantic_object=schema) # type: ignore[type-var, arg-type]