langchain - 💡(How to fix) Fix [Ollama][qwen] OllamaLLM.invoke() returns empty string with qwen3.5:9b model [4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36936Fetched 2026-04-23 07:23:13
View on GitHub
Comments
4
Participants
3
Timeline
11
Reactions
0
Author
Timeline (top)
labeled ×5commented ×3issue_type_added ×1mentioned ×1

Problem Description: When using OllamaLLM from langchain-ollama to call the qwen3.5:9b model, the invoke() method returns an empty string.

Expected Behavior: Should return a non-empty Chinese response.

Actual Behavior: Returns an empty string.

Additional Information:

  • ollama run qwen3.5:9b "你好" works normally from the command line
  • Direct requests call to the Ollama API works normally
  • Upgrading/downgrading langchain-ollama versions (0.1.3 → 0.2.0 → 1.1.0) has no effect
  • Setting num_predict=512, streaming=False, client_kwargs={"timeout": 120} has no effect
  • Using ChatOllama instead of OllamaLLM also has no effect

Error Message

Error Message and Stack Trace (if applicable)

响应: ''(Empty string, no error message)

Root Cause

Problem Description: When using OllamaLLM from langchain-ollama to call the qwen3.5:9b model, the invoke() method returns an empty string.

Expected Behavior: Should return a non-empty Chinese response.

Actual Behavior: Returns an empty string.

Additional Information:

  • ollama run qwen3.5:9b "你好" works normally from the command line
  • Direct requests call to the Ollama API works normally
  • Upgrading/downgrading langchain-ollama versions (0.1.3 → 0.2.0 → 1.1.0) has no effect
  • Setting num_predict=512, streaming=False, client_kwargs={"timeout": 120} has no effect
  • Using ChatOllama instead of OllamaLLM also has no effect

Fix Action

Fix / Workaround

  • 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.

Code Example

from langchain_ollama import OllamaLLM

llm = OllamaLLM(model="qwen3.5:9b", temperature=0.3)
response = llm.invoke("你好,请用一句话回答")
print(f"响应: '{response}'")

# Expected output: non-empty string
# Actual output: Response: '' (empty string)


# Comparison: Directly calling Ollama API works normally 

import requests

response = requests.post(
"http://localhost:11434/api/generate",
json = {"model": "qwen3.5:9b", "prompt": "你好", "stream": False} timeout=120
)
print(response.json().get("response", ""))
# Normal response in Chinese

---

响应: ''(Empty string, no error message)
RAW_BUFFERClick to expand / collapse

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-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_ollama import OllamaLLM

llm = OllamaLLM(model="qwen3.5:9b", temperature=0.3)
response = llm.invoke("你好,请用一句话回答")
print(f"响应: '{response}'")

# Expected output: non-empty string
# Actual output: Response: '' (empty string)


# Comparison: Directly calling Ollama API works normally 

import requests

response = requests.post(
"http://localhost:11434/api/generate",
json = {"model": "qwen3.5:9b", "prompt": "你好", "stream": False} timeout=120
)
print(response.json().get("response", ""))
# Normal response in Chinese

Error Message and Stack Trace (if applicable)

响应: ''(Empty string, no error message)

Description

Problem Description: When using OllamaLLM from langchain-ollama to call the qwen3.5:9b model, the invoke() method returns an empty string.

Expected Behavior: Should return a non-empty Chinese response.

Actual Behavior: Returns an empty string.

Additional Information:

  • ollama run qwen3.5:9b "你好" works normally from the command line
  • Direct requests call to the Ollama API works normally
  • Upgrading/downgrading langchain-ollama versions (0.1.3 → 0.2.0 → 1.1.0) has no effect
  • Setting num_predict=512, streaming=False, client_kwargs={"timeout": 120} has no effect
  • Using ChatOllama instead of OllamaLLM also has no effect

System Info

System Information

OS: Windows OS Version: 10.0.26200 Python Version: 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 0.3.84 langchain: 0.3.28 langchain_community: 0.3.31 langsmith: 0.4.37 langchain_ollama: 0.3.10 langchain_text_splitters: 0.3.11

Other Dependencies

ollama: 0.21.0

extent analysis

TL;DR

The issue with OllamaLLM from langchain-ollama returning an empty string when calling the qwen3.5:9b model can be fixed by investigating the differences in how the invoke() method and the direct requests call to the Ollama API handle the request, particularly focusing on headers, parameters, and encoding.

Guidance

  1. Compare Request Details: Compare the request headers, parameters, and body sent by OllamaLLM's invoke() method with those sent by the direct requests call to identify any discrepancies that could cause the empty response.
  2. Check Encoding and Decoding: Verify that the encoding and decoding of the prompt and response are correctly handled in both scenarios, as character encoding issues could lead to empty or malformed responses.
  3. Inspect invoke() Method: Look into the implementation of the invoke() method in OllamaLLM to ensure it correctly constructs and sends the request to the Ollama API, paying attention to any potential issues with the model specification, temperature, or other parameters.
  4. Test with Different Models: Attempt to use OllamaLLM with different models to see if the issue is specific to the qwen3.5:9b model or if it's a more general problem with the invoke() method.

Example

No specific code example can be provided without modifying the existing OllamaLLM class or the invoke() method. However, adding logging or debugging statements to the invoke() method to inspect the request being sent and the response being received could help identify the issue.

Notes

The problem might be related to how the langchain-ollama package interacts with the Ollama API, possibly due to differences in request construction or parameter handling. The fact that direct requests calls and command-line usage of ollama work correctly suggests the issue is isolated to the OllamaLLM implementation.

Recommendation

Apply a workaround by using the direct requests call to the Ollama API until the issue with OllamaLLM is resolved, as this approach has been shown to work correctly in the provided example.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING