feat: add JSON structured output support to BedrockChatGenerator#3108
feat: add JSON structured output support to BedrockChatGenerator#3108davidsbatista wants to merge 24 commits intomainfrom
BedrockChatGenerator#3108Conversation
…icts + updating tests
BedrockChatGenerator
BedrockChatGeneratorBedrockChatGenerator
Coverage report (amazon_bedrock)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||
| region_name=aws_region_name, | ||
| profile_name=aws_profile_name, | ||
| ) | ||
| session = aiobotocore.session.AioSession() |
There was a problem hiding this comment.
could you explain why the aws_* variables are not passed in? I'm not familiar with aiobotocore and haven't found comprehensive docs...
There was a problem hiding this comment.
Ok I see we use them at client creation below. In any case, feel free to add details if relevant
| aws_access_key_id: Secret | None = None, | ||
| aws_secret_access_key: Secret | None = None, | ||
| aws_session_token: Secret | None = None, | ||
| aws_region_name: Secret | None = None, | ||
| aws_profile_name: Secret | None = None, |
There was a problem hiding this comment.
we use this pattern across all integrations, so I don't see the need for changing it.
The docstring also generates the API reference, which makes it clear to users what the default value is.
There was a problem hiding this comment.
this was a mistake, thanks for catching it!
| - `stopSequences`: List of stop sequences to stop generation. | ||
| - `temperature`: Sampling temperature. | ||
| - `topP`: Nucleus sampling parameter. | ||
| - `json_schema`: Request structured JSON output validated against a schema. Provide a dict with: |
There was a problem hiding this comment.
Instead of json_schema, I'd use response_format, which is more adopted across integrations
There was a problem hiding this comment.
I can expose it like that, but then I guess for the API to process it, I have to rename it to json_schema before it is sent
There was a problem hiding this comment.
actually it might not be needed
| - `temperature`: Sampling temperature. | ||
| - `topP`: Nucleus sampling parameter. | ||
| - `json_schema`: Request structured JSON output validated against a schema. See | ||
| :meth:`_prepare_request_params` for full details. |
There was a problem hiding this comment.
- we generally don't use
:meth:syntax - I would not point users to a private method (not available on the API reference). If we want to avoid duplications, let's point users to
__init__
| return replies | ||
|
|
||
|
|
||
| def _parse_structured_output(replies: list[ChatMessage]) -> list[ChatMessage]: |
There was a problem hiding this comment.
I'd prefer to leave JSON parsing to users, as we do in other integrations.
| - `temperature`: Sampling temperature. | ||
| - `topP`: Nucleus sampling parameter. | ||
| - `json_schema`: Request structured JSON output validated against a schema. See | ||
| :meth:`_prepare_request_params` for full details. |
Related Issues
Proposed Changes:
This PR introduces two major changes.,
1. Structured output support (json_schema)
Pass a
json_schemadict ingeneration_kwargsto request validated JSON responses from the model. The generator builds the correct outputConfig for the Bedrock Converse API and stores the parsed result inreply.meta["structured_output"].2.
aioboto3→aiobotocore(async path)The
outputConfigrequiresboto3>=1.42.84, butaioboto3pinsaiobotocore==2.25.1which is incompatible with that version of botocore at runtime. Replacedaioboto3withaiobotocore>=3.4.0directly — same underlying library, no functional change to async behaviour, resolves the version conflict.Files changed
How did you test it?
Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.