Skip to content

fix(core): allow input_json_delta aggregation for anthropic tool_use …#10923

Open
Arjun Shenoy (noishey) wants to merge 8 commits into
langchain-ai:mainfrom
noishey:fix/anthropic-structured-streaming
Open

fix(core): allow input_json_delta aggregation for anthropic tool_use …#10923
Arjun Shenoy (noishey) wants to merge 8 commits into
langchain-ai:mainfrom
noishey:fix/anthropic-structured-streaming

Conversation

@noishey
Copy link
Copy Markdown

Description

Fixes a critical regression introduced in v1.1.46 that breaks withStructuredOutput().stream() for Anthropic models.

Root Cause

Anthropic's streaming protocol uses an asymmetric naming convention during tool execution:

  1. Initial frame emits: type: "tool_use"
  2. Subsequent delta frames emit: type: "input_json_delta"

getMergeableTypeBase() normalizes input_json_delta to input_json. Because "input_json" !== "tool_use", the strict nominal type check introduced in PR #10790 flags this as a type mismatch and rejects the merge, throwing an OUTPUT_PARSING_FAILURE.

Solution

Explicitly map input_json_delta and input_json to return "tool_use" within getMergeableTypeBase(). This bridges the structural protocol gap, satisfies the type invariance check, and allows streamed JSON fragments to aggregate seamlessly.

Related Issues

Closes #10907


Author: @noishey

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: 579a400

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@langchain/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@christian-bromann
Copy link
Copy Markdown
Member

Thanks for the PR! Do you think we can add unit tests, e.g. in the Anthropic provider package verifying this works?

@noishey
Copy link
Copy Markdown
Author

Absolutely! I can definitely add some unit tests for this. I'll update the PR as soon as they are ready!

christian-bromann

This comment was marked as outdated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one minor nit

});
});

test("should successfully aggregate tool_use and input_json_delta chunks via .concat()", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like this test doesn't use any primitives exported in the Anthropic package, so can we move it into the core workspace?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure.

@noishey Arjun Shenoy (noishey) force-pushed the fix/anthropic-structured-streaming branch from 55aab9c to 91a57ae Compare May 19, 2026 14:36
@noishey Arjun Shenoy (noishey) force-pushed the fix/anthropic-structured-streaming branch from 91a57ae to 57287bb Compare May 19, 2026 14:45
});
});

test("should successfully aggregate tool_use and input_json_delta chunks via .concat()", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we move this test into @langchain/core?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sure.

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.

@langchain/core 1.1.46 breaks withStructuredOutput streaming for Anthropic models

2 participants