Skip to content

feat(event_handler): allow custom serializer on BedrockAgentResolver#8271

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
kimnamu:feat/bedrock-agent-serializer
Jun 18, 2026
Merged

feat(event_handler): allow custom serializer on BedrockAgentResolver#8271
leandrodamascena merged 2 commits into
aws-powertools:developfrom
kimnamu:feat/bedrock-agent-serializer

Conversation

@kimnamu

@kimnamu kimnamu commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8270

Summary

Changes

BedrockAgentResolver is the only OpenAPI resolver that doesn't expose serializer, so non-ASCII Bedrock Agent responses can't avoid \uXXXX escaping. This exposes the parent ApiGatewayResolver's existing serializer argument on BedrockAgentResolver and passes it through — matching the sibling BedrockAgentFunctionResolver, which already accepts serializer (and the approach the maintainer endorsed in #7776 / #6394).

User experience

Item Before After
BedrockAgentResolver(serializer=...) TypeError: unexpected keyword 'serializer' ✅ accepted
Korean/emoji response body 잔액... escaped 잔액은 1,000원입니다 💰 (with ensure_ascii=False)
Default behavior (no serializer) escapes non-ASCII ✅ unchanged
Public API / other args / response shape ✅ unchanged (additive optional kwarg)

Out of scope (follow-up): defaulting the builder to ensure_ascii=False (a behavior change) — intentionally not done here.

Checklist

  • Tests: 2 new GIVEN/WHEN/THEN tests in _pydantic/test_bedrock_agent.py (default escapes; custom partial(json.dumps, ensure_ascii=False) preserves non-ASCII). Reverting the source change (keeping tests) → TypeError: ... unexpected keyword argument 'serializer'; restored → 17 passed. ruff/mypy clean.

This contribution was prepared with the help of an AI agent (Claude Code); a human reviewed the change, rationale, and test results before submission.


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

BedrockAgentResolver did not expose the `serializer` parameter that its
parent ApiGatewayResolver and its sibling BedrockAgentFunctionResolver
already accept, so there was no way to override the default
`ensure_ascii=True` serialization. Non-ASCII agent responses (e.g.
Korean/Japanese/emoji) were therefore always \uXXXX-escaped in
responseBody.body.

Expose the existing parent `serializer` argument and pass it through to
super().__init__, matching the sibling resolver.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kimnamu kimnamu requested a review from a team as a code owner June 13, 2026 14:12
@kimnamu kimnamu requested a review from hjgraca June 13, 2026 14:12
@boring-cyborg

boring-cyborg Bot commented Jun 13, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 13, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 18, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.58%. Comparing base (c0804d4) to head (27c13bc).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8271   +/-   ##
========================================
  Coverage    96.58%   96.58%           
========================================
  Files          286      286           
  Lines        14294    14294           
  Branches      1192     1192           
========================================
  Hits         13806    13806           
  Misses         357      357           
  Partials       131      131           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @kimnamu! Approved!

@leandrodamascena leandrodamascena merged commit f7239b8 into aws-powertools:develop Jun 18, 2026
17 checks passed
@boring-cyborg

boring-cyborg Bot commented Jun 18, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: allow customizing serializer on BedrockAgentResolver (parity with BedrockAgentFunctionResolver)

2 participants