AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

_Extract_reasoning_from_additional_kwargs Should Ignore Empty Strings

The function returns a reasoning content block even when the reasoning_content string is empty, causing alternating empty reasoning blocks in content_blocks when using LC_OUTPUT_VERSION=v1.

mediumConfidence 95%LangchainAgentsEmbeddingsAffected V<=1.2.13

Origin Analysis

The condition does not check for empty string after verifying the type is str, so an empty string passes the check and produces a block with empty reasoning.
1. Instantiate a BaseMessage with additional_kwargs={'reasoning_content': ''}. 2. Call _extract_reasoning_from_additional_kwargs on that message. 3. Observe that it returns {'type': 'reasoning', 'reasoning': ''} instead of None.

Fixing Code Block

def _extract_reasoning_from_additional_kwargs( message: BaseMessage, ) -> types.ReasoningContentBlock | None: """Extract `reasoning_content` from `additional_kwargs`. Handles reasoning content stored in various formats: - `additional_kwargs["reasoning_content"]` (string) - Ollama, DeepSeek, XAI, Groq Args: message: The message to extract reasoning from. Returns: A `ReasoningContentBlock` if reasoning content is found, None otherwise. """ additional_kwargs = getattr(message, "additional_kwargs", {}) reasoning_content = additional_kwargs.get("reasoning_content") if reasoning_content is not None and isinstance(reasoning_content, str) and reasoning_content: return {"type": "reasoning", "reasoning": reasoning_content} return None
Added `and reasoning_content` to the condition to ensure empty strings are not treated as valid reasoning blocks.

Edge Case Audit

This change will skip empty reasoning strings entirely. If any downstream logic relies on receiving empty reasoning blocks (unlikely), it may need adjustment. Rollback: remove the added `and reasoning_content` condition.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state