Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/partners/ollama/langchain_ollama/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,11 @@ def _chat_params(
**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

Expand Down
26 changes: 26 additions & 0 deletions libs/partners/ollama/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading