fix: handle missing optional fields in non-streaming citation conversion#2098
Merged
mkmeral merged 1 commit intostrands-agents:mainfrom Apr 9, 2026
Merged
Conversation
Nova grounding returns citations with only url/domain in location but no title or sourceContent fields. The non-streaming to streaming conversion in _convert_non_streaming_to_streaming accessed these fields directly (citation["title"]) causing KeyError. Changed to conditional inclusion using 'in' checks, matching the existing pattern in _format_request_message_content (line 668) and consistent with CitationsDelta being TypedDict(total=False).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
pgrayy
approved these changes
Apr 9, 2026
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.
Non-streaming Bedrock responses with
citationsContentcrash withKeyError: 'title'when Nova grounding returns citations without optional fields.Why
Nova's web grounding returns citations containing only
location(withurlanddomain) but notitleorsourceContentfields. The_convert_non_streaming_to_streamingmethod accesses these fields directly (citation["title"]), causing aKeyError.The SDK's own
CitationsDeltatype isTypedDict(total=False)— all fields are optional. And the same file already handles this correctly in_format_request_message_contentusingif "title" in citationchecks. The non-streaming conversion path was the only place that didn't follow this pattern.What changed
src/strands/models/bedrock.py— Changed_convert_non_streaming_to_streamingto conditionally include citation fields only when present, matching the existing safe pattern elsewhere in the file.tests/strands/models/test_bedrock.py— Added three test cases:location(minimal citation)Reproduction
Related: #1154, #1318, #1323