Skip to content

Conversation

dbschmigelski
Copy link
Member

@dbschmigelski dbschmigelski commented Sep 10, 2025

Description

This PR fixes a problem with AWS Bedrock's strict API validation. Bedrock throws validation exceptions when it receives unexpected fields in content blocks, unlike other model providers that ignore unknown fields. This means we need to filter all content blocks before sending them to Bedrock.

The current implementation only handles tool result blocks with hardcoded filtering. But Bedrock supports many content block types (image, document, video, reasoning, citations, cache points, guard content, etc.), each with different field requirements. The hardcoded approach doesn't scale as we add support for more content types.

This refactor adds a mapping of all Bedrock content block types (not text) to their allowed fields, pulled from AWS API documentation. The filtering logic now works with any content block type, so adding new block types just requires updating the field mapping.

Related Issues

#341
#343

Documentation PR

N/A

Type of Change

Chore to allow future change

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dbschmigelski dbschmigelski changed the title chore: filter all ContentBlock fields in BedrockModel chore: validate all ContentBlock fields in BedrockModel Sep 10, 2025
@dbschmigelski dbschmigelski marked this pull request as ready for review September 10, 2025 17:52
}, # https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolUseBlock.html
"document": {
"name",
"source",
Copy link
Member

Choose a reason for hiding this comment

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

Chatted with @dbschmigelski a bit about this. I think we need to do a deeper check then this in order to validate the incoming content type. Document source can have many different values, some that may not be valid in bedrock. For example, bedrock supports S3 as a location (ref), but does not support url locations, which we have a request for (ref).

Lets maybe instead add some switch-case logic to map content that is not one-to-one for the bedrock shape.

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