Skip to content

Instantly share code, notes, and snippets.

@Jordanh1996
Jordanh1996 / repro_empty_tool_result.py
Last active April 26, 2026 13:38
Reproduction: langchain-google-vertexai _merge_messages drops tool_result for empty ToolMessage content
"""Reproduction: _merge_messages in langchain-google-vertexai silently drops
tool_result when ToolMessage has empty content (content=[]).
Bug:
_merge_messages in langchain_google_vertexai/_anthropic_utils.py treats
ToolMessage(content=[]) as pre-formatted tool_result blocks because
Python's `all(predicate for x in [])` returns True on an empty iterable.
The empty list becomes HumanMessage([]), which then gets merged into the
next HumanMessage, silently dropping the tool_result. The Anthropic API
@Jordanh1996
Jordanh1996 / repro_prompt_too_long.py
Created March 27, 2026 20:57
Reproduction: SummarizationMiddleware token underestimation with ChatAnthropicVertex
"""Reproduction: SummarizationMiddleware token underestimation with ChatAnthropicVertex.
LangChain's _get_approximate_token_counter checks model._llm_type == "anthropic-chat",
but ChatAnthropicVertex._llm_type returns "anthropic-chat-vertexai". This causes the
token counter to use 4.0 chars/token instead of 3.3, underestimating by ~16%.
The summarization middleware never triggers, and the API rejects the prompt.
Additionally:
- use_usage_metadata_scaling is gated on response_metadata["model_provider"], which
ChatAnthropicVertex never sets. The scaling safety net is a no-op.