High severity beginner · Fix: 2-5 min

ValueError

langchain.callbacks.streaming_stdout.ValueError

What this error means
LangChain raises this error when a streaming LLM call is made without setting a streaming callback handler to process token-by-token output.

Stack trace

traceback
ValueError: Streaming callback not set. Please provide a streaming callback handler to receive tokens.
  File "/path/to/langchain/callbacks/streaming_stdout.py", line 45, in on_llm_new_token
    raise ValueError("Streaming callback not set.")
  File "app.py", line 27, in <module>
    response = llm(..., streaming=True)  # triggers error
QUICK FIX
Add StreamingStdOutCallbackHandler() to your LLM's callbacks parameter when using streaming=True.

Why it happens

LangChain's streaming LLM calls require a callback function or handler to process tokens as they stream in. If you enable streaming but do not provide a callback, LangChain cannot deliver the streamed tokens and raises this error to prevent silent failures.

Detection

Check if your LLM call uses streaming=True without passing a streaming callback or handler; logging or debugging will show this ValueError before your app hangs or silently fails.

Causes & fixes

1

Streaming enabled but no streaming callback handler provided

✓ Fix

Pass a valid streaming callback handler such as StreamingStdOutCallbackHandler() or a custom callback to the LLM constructor or call.

2

Using LangChain LLM wrapper without configuring callbacks for streaming

✓ Fix

Instantiate the LLM with callbacks=[StreamingStdOutCallbackHandler()] or your own callback list to handle streaming tokens.

3

Custom LLM wrapper disables or omits streaming callback setup

✓ Fix

Ensure your custom wrapper or subclass properly forwards streaming callbacks to the underlying LangChain LLM client.

Code: broken vs fixed

Broken - triggers the error
python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model_name="gpt-4o-mini", streaming=True)
response = llm("Hello")  # ValueError: Streaming callback not set error here
Fixed - works correctly
python
import os
from langchain_openai import ChatOpenAI
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "your_api_key_here")

llm = ChatOpenAI(model_name="gpt-4o-mini", streaming=True, callbacks=[StreamingStdOutCallbackHandler()])  # Added streaming callback
response = llm("Hello")
print(response)
Added StreamingStdOutCallbackHandler() to the callbacks list so the streaming tokens are handled properly, preventing the ValueError.

Workaround

Wrap the LLM call in try/except ValueError and catch the streaming callback error; then log a warning and fallback to non-streaming calls.

Prevention

Always configure streaming callbacks explicitly when enabling streaming in LangChain LLM calls to ensure tokens are processed and avoid runtime errors.

Python 3.9+ · langchain-core >=0.1.0 · tested on 0.2.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.