kmail.at
← learning

langchain · difficulty ◆◆

Keep the First Token: content_block_start in Anthropic Streaming

Fix silent streaming data loss from Claude

Your streamed Claude responses were losing their first word without you noticing.

2026-07-03 · 6 min read

$ pip install -U langchain-anthropic>=1.4.8

What it does

When streaming Claude responses through LangChain, the content_block_start event was silently dropping the initial text chunk of the assistant message. langchain-anthropic 1.4.8 preserves the initial text that arrives in the first content_block_start callback, so the model no longer appears to jump in partway through its own sentence.

Why it matters

Streaming is what makes LLM apps feel alive. Users expect tokens to appear progressively, not in sudden bursts. If the opening words vanish, the output reads as truncated or incoherent right at the start, which is especially jarring for longer generations. Any app using stream_events, astream, or plain stream with langchain-anthropic benefits from this fix.

Example

$ Stream a Claude reply with astream_events and confirm the first word is present.
Full response: Quantum entanglement is a phenomenon where two particles become
interconnected so that the quantum state of one instantly influences the other,
regardless of the distance between them.

Before 1.4.8 the response could start mid-sentence, skipping the opening word.

Common flags

ChatAnthropic.stream()
Synchronous streaming, affected by the fix
ChatAnthropic.astream()
Async streaming, affected by the fix
astream_events()
Low-level event stream; on_chat_model_stream now includes the full initial chunk
ChatAnthropic.invoke()
Non-streaming invocation, not affected

History

Origin

The bug surfaced from how the Anthropic SDK frames streaming events. A content_block_start marker and the first text delta could land in a single chunk, and LangChain was only forwarding the marker while dropping the accompanying text.

The fix

PR #38442, titled fix(anthropic): keep initial text on content_block_start, made the integration merge the text that shares a chunk with the block start marker.

Fun facts

Pros & cons

pros

  • + Removes silent token loss
  • + No code changes required
  • + Fixes both sync and async streaming

cons

  • − Only addresses Anthropic streaming
  • − Requires a package upgrade to take effect

Takeaways

  1. 1Check streaming output starts clean
  2. 2Treat content_block_start as possibly carrying text
  3. 3Upgrade partner packages for silent data-loss fixes

Related commands

← all learning