Skip to content

Commit 0dbac63

Browse files
docs: clarify BedrockResponse.is_json() always returns True (#7748)
Addresses #7692 - Added comprehensive docstring to BedrockResponse.is_json() explaining why it always returns True regardless of content_type parameter - Updated BedrockResponse class docstring with note about Bedrock Agents only supporting TEXT content type - Added tip in bedrock_agents.md documentation to clarify content_type behavior for users - Included AWS documentation reference for context The content_type parameter is maintained for API consistency but does not affect the actual response format sent to Bedrock Agents, as they only support TEXT content type per AWS Lambda integration docs. Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
1 parent 7f5e991 commit 0dbac63

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ class BedrockResponse(Generic[ResponseT]):
261261
"""
262262
Contains the response body, status code, content type, and optional attributes
263263
for session management and knowledge base configuration.
264+
265+
Note
266+
----
267+
Amazon Bedrock Agents only support TEXT content type in the responseBody according to the
268+
Lambda integration documentation. As a result, all response bodies are automatically serialized
269+
as JSON strings regardless of the content_type parameter. The content_type parameter is maintained
270+
for API consistency but does not affect the actual format sent to Bedrock Agents.
271+
272+
See: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html
264273
"""
265274

266275
def __init__(
@@ -282,6 +291,18 @@ def __init__(
282291
def is_json(self) -> bool:
283292
"""
284293
Returns True if the response is JSON, based on the Content-Type.
294+
295+
Note
296+
----
297+
This method always returns True for BedrockResponse regardless of the content_type parameter.
298+
This is because Amazon Bedrock Agents only support TEXT content type in the responseBody,
299+
and the event handler automatically serializes all response bodies as JSON strings when
300+
sending to Bedrock Agents.
301+
302+
See: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html
303+
304+
The content_type parameter in BedrockResponse is maintained for API consistency but does not
305+
affect the actual response format sent to Bedrock Agents.
285306
"""
286307
return True
287308

docs/core/event_handler/bedrock_agents.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ You can enable user confirmation with Bedrock Agents to have your application as
333333

334334
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"}.
335335

336+
???+ tip "Content Type Behavior"
337+
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.
338+
339+
Learn more: [AWS Bedrock Lambda Integration](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html){target="_blank"}
340+
336341
```python title="working_with_bedrockresponse.py" title="Customzing your Bedrock Response" hl_lines="5 16"
337342
--8<-- "examples/event_handler_bedrock_agents/src/working_with_bedrockresponse.py"
338343
```

0 commit comments

Comments
 (0)