The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(ollama): pop unsupported 'strict' argument in `ChatOllama` (#34114)
dumko200105ba853548b7
diff --git a/libs/partners/ollama/langchain_ollama/chat_models.py b/libs/partners/ollama/langchain_ollama/chat_models.pyindex 890f47f39d..c5667bec72 100644--- a/libs/partners/ollama/langchain_ollama/chat_models.py+++ b/libs/partners/ollama/langchain_ollama/chat_models.py@@ -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"] = toolsdiff --git a/libs/partners/ollama/tests/unit_tests/test_chat_models.py b/libs/partners/ollama/tests/unit_tests/test_chat_models.pyindex 666d487795..34413e7fe1 100644--- a/libs/partners/ollama/tests/unit_tests/test_chat_models.py+++ b/libs/partners/ollama/tests/unit_tests/test_chat_models.py@@ -410,3 +410,29 @@ def test_explicit_options_dict_preserved() -> None:# Explicit options should be preserved as-isassert 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