Skip to content

langchain-ollama allows ollama<0.6.3, which rejects model-defined thinking levels with a Pydantic ValidationError #40987

Description

Submission checklist

  • 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 posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-typesafe
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

Upstream client fix, already merged and released as ollama 0.6.3:
ollama/ollama-python#744

Reproduction Steps / Example Code (Python)

from langchain_core.messages import HumanMessage
from langchain_ollama import ChatOllama
from ollama._types import ChatRequest

model = ChatOllama(
    model="qwen3:8b",
    base_url="http://localhost:11434",
    reasoning="xhigh",
)

params = model._chat_params([HumanMessage("hi")])
assert params["think"] == "xhigh"

ChatRequest(
    messages=[{"role": "user", "content": "hi"}],
    model="qwen3:8b",
    think=params["think"],
)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "repro.py", line 9, in <module>
    ChatRequest(messages=[{"role": "user", "content": "hi"}], model="qwen3:8b", think=params["think"])
  File "/venv/lib/python3.14/site-packages/pydantic/main.py", line 263, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for ChatRequest
think.bool
  Input should be a valid boolean, unable to interpret input [type=bool_parsing, input_value='xhigh', input_type=str]
    For further information visit https://errors.pydantic.dev/2.13/v/bool_parsing
think.literal['low','medium','high']
  Input should be 'low', 'medium' or 'high' [type=literal_error, input_value='xhigh', input_type=str]
    For further information visit https://errors.pydantic.dev/2.13/v/literal_error

Description

I'm trying to run an agent on a local Ollama model that advertises its own thinking levels through /api/show, and I set reasoning on ChatOllama to one of those model-defined levels ("xhigh").

I expect ChatOllama to forward the level to Ollama, since ChatOllama.reasoning is typed bool | str | None and _chat_params() passes it straight through as think. The Ollama Go backend accepts any bool or string for ThinkValue.

Instead I get a Pydantic ValidationError pointing into ollama/_types.py, before any request reaches Ollama. The traceback mentions nothing about a version mismatch, so it reads like a Pydantic bug rather than a resolvable dependency floor.

The cause is the declared dependency range in libs/partners/ollama/pyproject.toml:

"ollama>=0.6.1,<1.0.0",

In ollama 0.6.1 and 0.6.2, ChatRequest.think and GenerateRequest.think are annotated Optional[Union[bool, Literal["low", "medium", "high"]]]. ollama-python#744 relaxed all of these sites to Optional[Union[bool, str]], and that shipped in ollama 0.6.3 (2026-09-29). The floor was never raised to match, so the newest ollama a resolver may install for langchain-ollama 1.1.0 is 0.6.2 — the last version that cannot represent the values ChatOllama already accepts.

I verified this in both directions with the snippet above, changing nothing but the installed ollama version:

  • ollama==0.6.2 → ValidationError on think.bool and think.literal['low','medium','high']
    • ollama==0.6.3 → validates, and the annotation reads bool | str | None
      Proposed fix is a one-line floor bump in libs/partners/ollama/pyproject.toml:
-    "ollama>=0.6.1,<1.0.0",
- +    "ollama>=0.6.3,<1.0.0",
- ```
No `ChatOllama` code path needs to change. I considered narrowing or validating `reasoning` inside `ChatOllama` instead, but that would reject levels the Ollama backend accepts and would duplicate type logic the client now owns.

I would raise the floor rather than pin, so that anyone currently locked to 0.6.2 for unrelated reasons gets an actionable resolver error instead of a `ValidationError` raised from inside Pydantic.

Happy to open the PR for this once the approach is confirmed — I have the change ready as a single-line diff against `master`.

### System Info

System Information

OS: Linux
OS Version: #38-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 4 09:10:14 UTC 2026
Python Version: 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0]

Package Information

langchain_core: 1.6.4
langchain: 1.4.2
langsmith: 0.13.0
deepagents: 0.7.14
langchain_anthropic: 1.7.2
langchain_google_genai: 4.4.0
langchain_mcp_adapters: 0.3.2
langchain_ollama: 1.1.0
langchain_protocol: 0.0.19
langchain_text_splitters: 1.1.2
langgraph_sdk: 0.4.4

Optional packages not installed

deepagents-cli

Other Dependencies

anthropic: 1.7.0
anyio: 4.15.1
distro: 1.9.0
filetype: 1.2.0
google-genai: 2.24.0
httpx: 0.28.1
httpx2: 2.13.0
jsonpatch: 1.33
langgraph: 1.2.12
mcp: 1.30.0
ollama: 0.6.2
orjson: 3.12.0
packaging: 26.3
pydantic: 2.13.5
pytest: 9.1.1
pyyaml: 6.0.3
requests: 2.34.2
requests-toolbelt: 1.0.0
rich: 15.0.0
sniffio: 1.3.1
tenacity: 9.1.4
typing-extensions: 4.16.0
uuid-utils: 0.17.1
wcmatch: 11.0.1
websockets: 16.1.1
xxhash: 4.0.1
zstandard: 0.25.0


### Social handles (optional)

_No response_

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featureexternalollama`langchain-ollama` package issues & PRs

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions