Repository: aws-powertools/powertools-lambda-python

Issue:
Bug: Powertools Bedrock Resolver truncates parameters with commas
### Expected Behaviour

Given an input:

```json
{
        "apiPath": "/sql-query",
        "httpMethod": "POST",
        "inputText": "<some irrelevant text>",
        "actionGroup": "test-group",
        "parameters": [
        {
            "name": "query",
            "type": "string",
            "value": "SELECT a.source_name, b.thing FROM table"
        }]
}
```

The expected parameters passed to the function registered at the endpoint should include the entire query:

```python
@app.post("/sql-query...)
def my_func(query: Annotated[str,...]):
    print(query)
```

### Current Behaviour

Currently, the above code prints "SELECT a.source_name". I've validated that it works correctly with queries without commas. I am unaware of any other characters that cause this behavior.

### Code snippet

See above. This can be easily recreated by passing a Bedrock action group query parameter with a comma in it to the resolver.

### Possible Solution

This may be related to how the resolver inherits from the ApiGateway resolver and passes the parameters as query parameters.

### Steps to Reproduce

1. Create a Bedrock Agent Resolver instance and add a POST route with a string parameter
2. Pass a valid minimum test payload to the handler instance with a parameter value including a comma, such as a complex SQL query
3. Check the parameter as passed to the route function

### Powertools for AWS Lambda (Python) version

latest

### AWS Lambda function runtime

3.12

### Packaging format used

Lambda Layers

### Debugging logs

```python

```


Discussion:
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: [Invite link](https://discord.gg/B8zZKbbyET)

Hi @mkkatica, thanks for opening this issue! I think I know what's going on here! When we [parse](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/common.py#L172) the event that tries to determine if the request contains a multi-valued parameter, we are incorrectly parsing data where the comma is actually expected, as in your case.

I need to see how to fix this, but will add in our backlog to take a look this week.
Thanks @leandrodamascena! I was able to work around this by reading the event directly in my route function using `app.current_event` for now, but it will be nice to have it parse correctly.



Patch:
diff --git a/aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py b/aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py
index 1b3c57be124..ad1fae31518 100644
--- a/aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py
+++ b/aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py
@@ -112,6 +112,19 @@ def query_string_parameters(self) -> dict[str, str]:
         parameters = self.get("parameters") or []
         return {x["name"]: x["value"] for x in parameters}
 
+    @property
+    def resolved_query_string_parameters(self) -> dict[str, list[str]]:
+        """
+        Override the base implementation to prevent splitting parameter values by commas.
+
+        For Bedrock Agent events, parameters are already properly structured and should not
+        be split by commas as they might contain commas as part of their actual values
+        (e.g., SQL queries).
+        """
+        # Return each parameter value as a single-item list without splitting by commas
+        parameters = self.get("parameters") or []
+        return {x["name"]: [x["value"]] for x in parameters}
+
     @property
     def resolved_headers_field(self) -> dict[str, Any]:
         return {}
diff --git a/aws_lambda_powertools/utilities/data_classes/common.py b/aws_lambda_powertools/utilities/data_classes/common.py
index ecc9a2033ab..f6a6b3e5a0e 100644
--- a/aws_lambda_powertools/utilities/data_classes/common.py
+++ b/aws_lambda_powertools/utilities/data_classes/common.py
@@ -168,7 +168,7 @@ def query_string_parameters(self) -> dict[str, str]:
     def multi_value_query_string_parameters(self) -> dict[str, list[str]]:
         return self.get("multiValueQueryStringParameters") or {}
 
-    @cached_property
+    @property
     def resolved_query_string_parameters(self) -> dict[str, list[str]]:
         """
         This property determines the appropriate query string parameter to be used


Test patch:
diff --git a/tests/functional/event_handler/_pydantic/test_bedrock_agent.py b/tests/functional/event_handler/_pydantic/test_bedrock_agent.py
index fff0f8b7d42..9c46fe24eb7 100644
--- a/tests/functional/event_handler/_pydantic/test_bedrock_agent.py
+++ b/tests/functional/event_handler/_pydantic/test_bedrock_agent.py
@@ -5,7 +5,7 @@
 from typing_extensions import Annotated
 
 from aws_lambda_powertools.event_handler import BedrockAgentResolver, BedrockResponse, Response, content_types
-from aws_lambda_powertools.event_handler.openapi.params import Body
+from aws_lambda_powertools.event_handler.openapi.params import Body, Query
 from aws_lambda_powertools.utilities.data_classes import BedrockAgentEvent
 from tests.functional.utils import load_event
 
@@ -343,3 +343,43 @@ def handler() -> Optional[Dict]:
 
     # THEN the OpenAPI schema must contain the "x-requireConfirmation" extension at the operation level
     assert schema["paths"]["/"]["get"]["x-requireConfirmation"] == "ENABLED"
+
+
+def test_bedrock_agent_with_comma_parameters():
+    # GIVEN a Bedrock Agent resolver
+    app = BedrockAgentResolver()
+
+    @app.post("/sql-query", description="Run a SQL query")
+    def run_sql_query(query: Annotated[str, Query()]):
+        return {"result": query}
+
+    # WHEN calling the event handler with a parameter containing commas
+    event = {
+        "actionGroup": "TestActionGroup",
+        "messageVersion": "1.0",
+        "sessionId": "12345678912345",
+        "sessionAttributes": {},
+        "promptSessionAttributes": {},
+        "inputText": "Run a SQL query",
+        "agent": {
+            "alias": "TEST",
+            "name": "test",
+            "version": "1",
+            "id": "test123",
+        },
+        "httpMethod": "POST",
+        "apiPath": "/sql-query",
+        "parameters": [
+            {
+                "name": "query",
+                "type": "string",
+                "value": "SELECT a.source_name, b.thing FROM table",
+            },
+        ],
+    }
+
+    result = app(event, {})
+
+    # THEN the parameter with commas should be correctly passed to the handler
+    body = json.loads(result["response"]["responseBody"]["application/json"]["body"])
+    assert body["result"] == "SELECT a.source_name, b.thing FROM table"