Updating Bedrock Converse API citations format to handle web citations#1168
Closed
danilop wants to merge 1 commit intostrands-agents:mainfrom
Closed
Updating Bedrock Converse API citations format to handle web citations#1168danilop wants to merge 1 commit intostrands-agents:mainfrom
danilop wants to merge 1 commit intostrands-agents:mainfrom
Conversation
dbschmigelski
suggested changes
Nov 13, 2025
| domain: str | ||
|
|
||
|
|
||
| class DocumentChunkLocation(TypedDict, total=False): |
Contributor
There was a problem hiding this comment.
Hi, we have to preserve backwards compatibility. So we cannot simply remove these classes.
These are typeddicts, so I see the argument that it would not be possible from someone to leverage
CitationLocation = Union[DocumentCharLocation, DocumentChunkLocation, DocumentPageLocation] to do instanceof checks in the first place. But this still needs to be workshopped to avoid breaking changes
Contributor
|
hi team, any update on this? One of my customer is also looking forward for this feature support to test out Nova Web Grounding. |
Contributor
Author
|
All types should be back now for backward compatibility. |
…rse API Add support for web-based citations in addition to document-based citations: - Added WebLocation TypedDict to citations.py with url and domain fields - Updated CitationLocation union to include WebLocation - Updated bedrock.py to filter web citation fields (url, domain only) - Handle optional citation fields gracefully (title, location, sourceContent) - Added tests for web citations, document citations, and edge cases
Contributor
Author
|
Closing this PR in favor of a cleaner split:
This separation keeps bug fixes and features in separate PRs as per best practices. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes citation location handling in the Bedrock Converse API to properly preserve the tagged union structure required by the API.
Problem:
The Bedrock API requires
CitationLocationto be a tagged union with exactly one wrapper key (web,documentChar,documentPage,documentChunk, orsearchResultLocation). The previous implementation was flattening document-based citations, causing validation errors like:Solution:
DocumentCharLocation, etc.) and inner content types (DocumentCharLocationInner, etc.)_format_citation_locationhelper method that preserves the union structure when filtering citation locationsSearchResultLocationtype for complete API coverageChanges:
src/strands/types/citations.py: Refactored types to model tagged union structure correctlysrc/strands/models/bedrock.py: Added_format_citation_locationhelper methodtests/strands/models/test_bedrock.py: Added tests for all citation location typesRelated Issues
Documentation PR
N/A
Type of Change
Bug fix
Testing
hatch run prepare(1616 tests pass)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.