Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ class BedrockResponse(Generic[ResponseT]):
"""
Contains the response body, status code, content type, and optional attributes
for session management and knowledge base configuration.

Note
----
Amazon Bedrock Agents only support TEXT content type in the responseBody according to the
Lambda integration documentation. As a result, all response bodies are automatically serialized
as JSON strings regardless of the content_type parameter. The content_type parameter is maintained
for API consistency but does not affect the actual format sent to Bedrock Agents.

See: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html
"""

def __init__(
Expand All @@ -282,6 +291,18 @@ def __init__(
def is_json(self) -> bool:
"""
Returns True if the response is JSON, based on the Content-Type.

Note
----
This method always returns True for BedrockResponse regardless of the content_type parameter.
This is because Amazon Bedrock Agents only support TEXT content type in the responseBody,
and the event handler automatically serializes all response bodies as JSON strings when
sending to Bedrock Agents.

See: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html

The content_type parameter in BedrockResponse is maintained for API consistency but does not
affect the actual response format sent to Bedrock Agents.
"""
return True

Expand Down
5 changes: 5 additions & 0 deletions docs/core/event_handler/bedrock_agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ You can enable user confirmation with Bedrock Agents to have your application as

You can use `BedrockResponse` class to add additional fields as needed, such as [session attributes, prompt session attributes, and knowledge base configurations](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html#agents-lambda-response){target="_blank"}.

???+ tip "Content Type Behavior"
Amazon Bedrock Agents only support TEXT content type in the responseBody. All response bodies are automatically serialized as JSON strings regardless of the `content_type` parameter you provide. The `content_type` parameter exists for API consistency but does not affect the actual format sent to Bedrock Agents.

Learn more: [AWS Bedrock Lambda Integration](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html){target="_blank"}

```python title="working_with_bedrockresponse.py" title="Customzing your Bedrock Response" hl_lines="5 16"
--8<-- "examples/event_handler_bedrock_agents/src/working_with_bedrockresponse.py"
```
Expand Down