sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

fix(bedrock): Fix KeyError for optional 'qualifiers' in guardContent

Open Ratish1 opened this issue 2 months ago • 4 comments

Description

This PR fixes a KeyError: 'qualifiers' that occurred when processing Bedrock guardContent. The original bug was caused by directly accessing the qualifiers field.

The change now assumes guardContent.text is a dictionary and safely checks for the existence of the optional qualifiers key before adding it to the result.

Related Issues

Closes #959

Documentation PR

N/A

Type of Change

Bug fix

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

  • [x] I ran hatch run prepare
  • [x] Pre-commit hooks, formatting and linting passed locally
  • [x] I ran unit tests for bedrock:
  • pytest -q tests/strands/models/test_bedrock.py::test_format_request_guard_content_with_qualifiers
  • pytest -q tests/strands/models/test_bedrock.py::test_format_request_guard_content_without_qualifiers

Checklist

  • [x] I have read the CONTRIBUTING document
  • [x] 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
  • [x] My changes generate no new warnings
  • [x] 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.

Ratish1 avatar Oct 03 '25 17:10 Ratish1