fix(ollama): pop unsupported 'strict' argument in ChatOllama (#34114)

This commit is contained in:
dumko2001
2025-12-12 19:43:11 +05:30
committed by GitHub
parent 3fb90666be
commit 05ba853548
2 changed files with 31 additions and 0 deletions

View File

@@ -774,6 +774,11 @@ class ChatOllama(BaseChatModel):
**kwargs,
}
# Filter out 'strict' argument if present, as it is not supported by Ollama
# but may be passed by upstream libraries (e.g. LangChain ProviderStrategy)
if "strict" in params:
params.pop("strict")
if tools := kwargs.get("tools"):
params["tools"] = tools

View File

@@ -410,3 +410,29 @@ def test_explicit_options_dict_preserved() -> None:
# Explicit options should be preserved as-is
assert options == {"temperature": 0.5, "custom_param": None}
def test_chat_ollama_ignores_strict_arg() -> None:
"""Test that ChatOllama ignores the 'strict' argument."""
response = [
{
"model": "test-model",
"created_at": "2025-01-01T00:00:00.000000000Z",
"done": True,
"done_reason": "stop",
"message": {"role": "assistant", "content": "Hello!"},
}
]
with patch("langchain_ollama.chat_models.Client") as mock_client_class:
mock_client = MagicMock()
mock_client_class.return_value = mock_client
mock_client.chat.return_value = response
llm = ChatOllama(model="test-model")
# Invoke with strict=True
llm.invoke([HumanMessage("Hello")], strict=True)
# Check that 'strict' was NOT passed to the client
call_kwargs = mock_client.chat.call_args[1]
assert "strict" not in call_kwargs