Skip to content

fix: Fix returned Anthropic reasoning blocks - #455

Open
jacoblee93 wants to merge 1 commit into
databricks:mainfrom
jacoblee93:jacob/reasoning
Open

fix: Fix returned Anthropic reasoning blocks#455
jacoblee93 wants to merge 1 commit into
databricks:mainfrom
jacoblee93:jacob/reasoning

Conversation

@jacoblee93

Copy link
Copy Markdown

Preserve structured content blocks returned by Databricks chat models instead of JSON-serializing them.

This fixes Anthropic reasoning responses where the initial streamed chunk contains a structured reasoning block and subsequent chunks contain answer text. Previously, LangChain combined these into a mixed list:

[reasoning_block, "answer text"]

Changes

  • Preserve list-based structured content in non-streaming and streaming message conversion.
  • After a structured streaming chunk is received, convert subsequent text deltas into indexed text blocks:
  [
      reasoning_block,
      {"type": "text", "text": "answer text", "index": 1},
  ]

@annzhang-db annzhang-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good, can we introduce something like output_version that langchain uses to make this behavior opt-in? just want to avoid breaking anything given the original pr for the string serialization mentions some downstream consumers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants