reasoning parameter not working as expected in chatollama
Opened this issue · 5 comments
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- This is not related to the langchain-community package.
- I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
if model_cfg.SUPPORTS_THINKING:
return ChatOllama(
model=llm_model_name,
temperature=temperature,
api_key=api_key,
base_url=api_url,
disable_streaming=not streaming,
reasoning=enable_think,
keep_alive=0,
)
else:
return ChatOllama(
model=llm_model_name,
temperature=temperature,
api_key=api_key,
base_url=api_url,
disable_streaming=not streaming,
keep_alive=0,
)
Error Message and Stack Trace (if applicable)
No response
Description
we have been uisng chatollama while invoking the ollama models.
here we are facing one issue.whenever we want to disable think content in the response body we are passing false flag to reasoning parameter,even though we are getting think content in the response body.
System Info
System Information
OS: Linux
OS Version: #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 14 16:52:50 UTC 2
Python Version: 3.11.11 (main, Dec 11 2024, 16:28:39) [GCC 11.2.0]
Package Information
langchain_core: 0.3.72
langsmith: 0.4.9
langgraph_sdk: 0.2.0
Optional packages not installed
langserve
Other Dependencies
httpx: 0.28.1
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
openai-agents: Installed. No version info available.
opentelemetry-api: Installed. No version info available.
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: Installed. No version info available.
orjson: 3.11.1
orjson>=3.10.1: Installed. No version info available.
packaging: 24.2
packaging>=23.2: Installed. No version info available.
pydantic: 2.10.3
pydantic>=2.7.4: Installed. No version info available.
pytest: 8.3.4
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
rich: 13.9.4
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0
What model(s) are you encountering this issue with? Some models don't allow disabling reasoning.
@mdrxy. we have used qwen3:4b to verify how reasoning parameter disables/enables the think content.
The same qwen models when invoked using groq(chatgroq) , were able to strip out think content successfully when reasoning is disabled.
I can't recreate this issue:
from langchain_ollama import ChatOllama
model = ChatOllama(model="qwen3:4b")
response = model.invoke("what is 3^3? explain your reasoning")
print(response.model_dump_json(indent=2))
model = ChatOllama(model="qwen3:4b", reasoning=False)
response = model.invoke("what is 3^3? explain your reasoning")
print(response.model_dump_json(indent=2))
model = ChatOllama(model="qwen3:4b", reasoning=True)
response = model.invoke("what is 3^3? explain your reasoning")
print(response.model_dump_json(indent=2))Neither case results in <think> tags shown.
Your example includes reasoning=enable_think which is not a valid option.
Could you provide a MRE?
try deepseek-r1:1.5b
model = ChatOllama(model="deepseek-r1:1.5b", reasoning=True)
response = model.invoke("what is 3^3? explain your reasoning")
print(response.model_dump_json(indent=2)){
"content": "**Solution:**\n\nTo find \\( 3^3 \\), we can break it down step by step using multiplication:\n\n1. **Understand the notation:** \n The expression \\( 3^3 \\) means \"3 multiplied by itself three times.\"\n\n2. **First multiplication:** \n Start with the base number, which is 3.\n\n3. **Second multiplication:** \n Multiply the result by 3 again:\n \\[\n 3 \\times 3 = 9\n \\]\n\n4. **Third multiplication:** \n Take the new result from the second multiplication and multiply it by 3 one more time:\n \\[\n 9 \\times 3 = 27\n \\]\n\n**Final Answer:**\n\\[\n3^3 = \\boxed{27}\n\\]",
"additional_kwargs": {
"reasoning_content": "First, I recognize that the expression \"3^3\" means 3 raised to the power of 3. To compute this, I can use multiplication.\n\nI start by multiplying 3 by itself once: 3 × 3 = 9.\n\nNext, I take the result from the first multiplication and multiply it by 3 again: 9 × 3 = 27.\n\nTherefore, 3 raised to the power of 3 equals 27.\n"
},
"response_metadata": {
"model": "deepseek-r1:1.5b",
"created_at": "2025-10-02T15:09:58.465058Z",
"done": true,
"done_reason": "stop",
"total_duration": 2151286458,
"load_duration": 48119792,
"prompt_eval_count": 13,
"prompt_eval_duration": 128325792,
"eval_count": 267,
"eval_duration": 1974373458,
"model_name": "deepseek-r1:1.5b",
"model_provider": "ollama"
},
"type": "ai",
"name": null,
"id": "lc_run--6b8fc5cd-f416-4630-b794-889d206c2b18-0",
"tool_calls": [],
"invalid_tool_calls": [],
"usage_metadata": {
"input_tokens": 13,
"output_tokens": 267,
"total_tokens": 280
}
}Still not encountering it. Are you on the latest version of langchain-ollama?