Skip to content

fix(amazon-bedrock): prevent double-wrapping of tools_cachepoint_config in _format_tools#3199

Merged
anakin87 merged 2 commits intodeepset-ai:mainfrom
Aftabbs:fix/amazon-bedrock-tools-cachepoint-double-wrap
Apr 22, 2026
Merged

fix(amazon-bedrock): prevent double-wrapping of tools_cachepoint_config in _format_tools#3199
anakin87 merged 2 commits intodeepset-ai:mainfrom
Aftabbs:fix/amazon-bedrock-tools-cachepoint-double-wrap

Conversation

@Aftabbs
Copy link
Copy Markdown
Contributor

@Aftabbs Aftabbs commented Apr 22, 2026

Summary

Fixes #3181

AmazonBedrockChatGenerator.__init__ pre-formats tools_cachepoint_config via _validate_and_format_cache_point, converting the user-supplied {"type": "default"} to {"cachePoint": {"type": "default"}} and storing it as self.tools_cachepoint_config.

_format_tools then received this already-formatted value and wrapped it a second time:

# before (broken)
tool_specs.append({"cachePoint": tools_cachepoint_config})
# → sent {"cachePoint": {"cachePoint": {"type": "default"}}} to Bedrock → ParamValidationError

Fix: append tools_cachepoint_config as-is since callers always pass the pre-formatted value:

# after (fixed)
tool_specs.append(tools_cachepoint_config)
# → sends {"cachePoint": {"type": "default"}} to Bedrock ✓

Changes

  • utils.py: remove the extra {"cachePoint": ...} wrapper in _format_tools
  • test_chat_generator_utils.py: update existing test_format_tools to pass the pre-formatted value (matching real call path from __init__); add test_format_tools_does_not_double_wrap_cachepoint regression test that chains _validate_and_format_cache_point_format_tools and asserts a single non-nested cachePoint entry

How to verify (no API key needed)

from haystack_integrations.components.generators.amazon_bedrock.chat.utils import (
    _validate_and_format_cache_point,
    _format_tools,
)
from haystack.tools import Tool

def think(thought: str) -> str:
    """Think step."""
    return ""

tool = Tool.from_function(think)
formatted = _validate_and_format_cache_point({"type": "default"})
result = _format_tools([tool], tools_cachepoint_config=formatted)
print(result["tools"][-1])
# before fix: {"cachePoint": {"cachePoint": {"type": "default"}}}
# after fix:  {"cachePoint": {"type": "default"}}  ✓

…ig in _format_tools

AmazonBedrockChatGenerator.__init__ pre-formats tools_cachepoint_config
via _validate_and_format_cache_point, producing {"cachePoint": {...}}.
_format_tools then wrapped it a second time, sending
{"cachePoint": {"cachePoint": {...}}} to Bedrock which rejected it with
ParamValidationError.

Fix: append tools_cachepoint_config as-is in _format_tools since callers
always pass the already-formatted value.

Also updates the existing test to pass the pre-formatted value (matching
real usage) and adds a regression test that chains both functions.

Fixes deepset-ai#3181
@Aftabbs Aftabbs requested a review from a team as a code owner April 22, 2026 05:42
@Aftabbs Aftabbs requested review from davidsbatista and removed request for a team April 22, 2026 05:42
@anakin87 anakin87 requested review from anakin87 and removed request for davidsbatista April 22, 2026 06:25
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

Thank you!

I also tested it locally and works well.

Just a minor format issue to solve...

Comment on lines +110 to +112
from haystack_integrations.components.generators.amazon_bedrock.chat.utils import (
_validate_and_format_cache_point,
)
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.

let's move the import at the top of the file

@github-actions
Copy link
Copy Markdown
Contributor

Coverage report (amazon_bedrock)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

👍

@anakin87 anakin87 merged commit 3aa2353 into deepset-ai:main Apr 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AmazonBedrockChatGenerator Bug: tools_cachepoint_config causes ParamValidationError

2 participants