langchain - 💡(How to fix) Fix Add support for Anthropic via Bedrock's `tool_search_tool_regex` in `ChatAnthropicBedrock` [4 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36128Fetched 2026-04-08 01:08:05
View on GitHub
Comments
4
Participants
2
Timeline
20
Reactions
0
Timeline (top)
mentioned ×5subscribed ×5commented ×4labeled ×4

When using Anthropic's tool search feature (tool_search_tool_regex) via Bedrock, the model returns tool_search_tool_result content blocks in its assistant messages. On subsequent turns, langchain-anthropic serializes these blocks back into the messages payload with an extra index field that the Bedrock API rejects:

anthropic.BadRequestError: Error code: 400 - 
{'message': 'messages.7.content.2.tool_search_tool_result.index: Extra inputs are not permitted'}

Attempting to use the anthropic tool defined here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-tool-use.html#model-parameters-anthropic-claude-tool-search-tool

Error Message

anthropic.BadRequestError: Error code: 400 - {'message': 'messages.7.content.2.tool_search_tool_result.index: Extra inputs are not permitted'}

Root Cause

When using Anthropic's tool search feature (tool_search_tool_regex) via Bedrock, the model returns tool_search_tool_result content blocks in its assistant messages. On subsequent turns, langchain-anthropic serializes these blocks back into the messages payload with an extra index field that the Bedrock API rejects:

anthropic.BadRequestError: Error code: 400 - 
{'message': 'messages.7.content.2.tool_search_tool_result.index: Extra inputs are not permitted'}

Attempting to use the anthropic tool defined here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-tool-use.html#model-parameters-anthropic-claude-tool-search-tool

Fix Action

Workaround

Stripping the index field from tool_search_tool_result content blocks in messages before calling ainvoke resolves the issue.

Code Example

anthropic.BadRequestError: Error code: 400 - 
{'message': 'messages.7.content.2.tool_search_tool_result.index: Extra inputs are not permitted'}
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

Package: langchain-anthropic v1.4.0

Description

When using Anthropic's tool search feature (tool_search_tool_regex) via Bedrock, the model returns tool_search_tool_result content blocks in its assistant messages. On subsequent turns, langchain-anthropic serializes these blocks back into the messages payload with an extra index field that the Bedrock API rejects:

anthropic.BadRequestError: Error code: 400 - 
{'message': 'messages.7.content.2.tool_search_tool_result.index: Extra inputs are not permitted'}

Attempting to use the anthropic tool defined here: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-tool-use.html#model-parameters-anthropic-claude-tool-search-tool

Reproduction

  1. Configure ChatAnthropicBedrock with the tool-search-tool-2025-10-19 beta and a tool_search_tool_regex entry in the tools array
  2. Mark at least one tool with defer_loading: True (via extras={"defer_loading": True} on a @tool)
  3. Send a message that triggers tool search — the model will return a tool_search_tool_result content block in its AIMessage
  4. On the next turn, when the conversation history (including the prior AIMessage) is sent back to the API, the serialized tool_search_tool_result block contains an index field that the API does not accept

Expected Behavior

tool_search_tool_result content blocks should be serialized without extra fields (like index) when passed back in conversation history, matching the Anthropic API schema.

Environment

  • anthropic: 0.86.0
  • langchain-anthropic: 1.4.0
  • langchain-core: (latest compatible)
  • Provider: anthropic_bedrock (us-east-1)
  • Beta: tool-search-tool-2025-10-19
  • Tool search type: tool_search_tool_regex

Workaround

Stripping the index field from tool_search_tool_result content blocks in messages before calling ainvoke resolves the issue.

Use Case

Simply being able to support the Anthropic defined tools that Bedrock makes available. These should work with langchain, given the fact I'm using ChatAnthropicBedrock, which inherits from ChatAnthropic.

Proposed Solution

No response

Alternatives Considered

No response

Additional Context

No response

extent analysis

Fix Plan

To resolve the issue, we need to modify the langchain-anthropic package to exclude the index field when serializing tool_search_tool_result content blocks.

Here are the steps:

  • Identify the function responsible for serializing tool_search_tool_result blocks in langchain-anthropic.
  • Modify this function to exclude the index field from the serialized output.
  • Example code snippet:
def serialize_tool_search_tool_result(block):
    # Existing code to serialize block...
    serialized_block = block.copy()
    # Remove the index field
    serialized_block.pop('index', None)
    return serialized_block
  • Update the ChatAnthropicBedrock class to use the modified serialization function when sending conversation history to the API.

Verification

To verify the fix, follow these steps:

  • Configure ChatAnthropicBedrock with the tool-search-tool-2025-10-19 beta and a tool_search_tool_regex entry in the tools array.
  • Send a message that triggers tool search and verify that the tool_search_tool_result block in the response does not contain an index field.
  • On subsequent turns, verify that the serialized tool_search_tool_result block in the conversation history does not contain an index field and that the API does not return a BadRequestError.

Extra Tips

  • Make sure to test the fix with different tool search scenarios to ensure that the index field is consistently excluded from the serialized output.
  • Consider adding a test case to the langchain-anthropic package to prevent regressions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING