fix(event-handler): preserve original string for invalid Bedrock Agent number params#5363
Conversation
…t number params The BedrockAgentFunctionResolver unconditionally coerced `number`/`integer` parameters with `Number(param.value)`, producing `NaN` (serialized to `null`) when the value is not a valid number. Fall back to the original string in that case, matching the Python runtime's `int()`/`float()` try/except behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
|
Thanks for the automated checks 🙏 A quick note on the Related Issue Check: the PR is correctly linked to #5362 ( I opened #5362 specifically because the original parity issue (#3988) is already closed/released, so I couldn't link to it directly — #5362 captures this remaining TypeScript-side gap. Happy to adjust the linkage if you'd prefer a different issue reference. The change itself is a small, test-covered cross-runtime parity fix (matches the Python |
dreamorosi
left a comment
There was a problem hiding this comment.
Thank you for the PR and for following the correct process & addressing CI checks.
|
Thanks for the nudge from the automation 🙏 I tracked down why the Related Issue Check kept failing even though The body also contained a bare I've rewritten that line so it no longer uses a bare This follow-up was prepared with the help of an AI agent (Claude Code); a human reviewed it before posting. |
|
The Related Issue Check is green now ✅ — the earlier failure was a stale run that didn't re-evaluate after I cleaned up the issue reference. The PR body now links exactly one issue ( This is approved and the merge state is clean — ready whenever you'd like to land it. Thanks again for the review! (This note was prepared with the help of an AI agent (Claude Code); I verified the check status and merge state before posting.) |



Summary
First, thank you to the maintainers for Powertools for AWS Lambda — it makes building Lambda functions a pleasure, and the cross-runtime parity work is much appreciated.
This is a small follow-up to that alignment effort. The
BedrockAgentFunctionResolvercoercesnumber/integerparameters withNumber(param.value)unconditionally. When a Bedrock Agent sends anumber/integer-typed parameter whose value is not a valid numeric string,Number(...)returnsNaN, which serializes tonullviaJSON.stringify— the original value sent by the agent is silently lost.The Python runtime already guards against this: it wraps
int()/float()intry/exceptand falls back to the original string (bedrock_agent_function.pyatL212-L221). This PR carries the same fallback over to the TypeScript resolver, so the two runtimes behave consistently.Changes
packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts— for thenumber/integercase, fall back to the original string whenNumber(...)yieldsNaN:This is the minimal change required: it touches only the
NaNbranch and leaves every other path untouched.Before / After
Tool that echoes back a
number-typed parameter with value'not-a-number':number/integerparam, non-numeric value ('not-a-number')NaN→ response bodynull(value lost)"not-a-number"preserved (matches Python)number/integerparam, valid value ('42')4242(unchanged)boolean/string/arrayparamsIssue number: Closes #5362
This continues the Bedrock Agent Function resolver alignment effort, which was previously tracked under the resolver parity work released in v2.21.0.
Testing
Added a parametrized regression test (
it.each(['number', 'integer'])) inpackages/event-handler/tests/unit/bedrock-agent/BedrockAgentFunctionResolver.test.tsasserting the original string is preserved.Green (with fix):
Red (fix reverted via
git stash, new test kept) — proves the test catches the bug:Local gates:
npx biome linton both changed files → clean.Statements 100% (33/33), Branches 100% (23/23), Functions 100% (4/4), Lines 100% (33/33)— the new branch is fully covered.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
This contribution was prepared with the help of an AI agent (Claude Code); a human reviewed the change, the rationale, and the test results before submitting.