@@ -2078,14 +2078,15 @@ async def test_citations_content_preserves_tagged_union_structure(bedrock_client
20782078
20792079 This test verifies that when messages contain citationsContent with tagged union CitationLocation objects,
20802080 the structure is preserved when sent to AWS Bedrock API. AWS Bedrock expects CitationLocation to be a
2081- tagged union with exactly one wrapper key (documentChar, documentPage, etc.) containing the location fields.
2081+ tagged union with exactly one wrapper key (documentChar, documentPage, documentChunk, searchResultLocation, web)
2082+ containing the location fields.
20822083 """
20832084 # Mock the Bedrock response
20842085 bedrock_client .converse_stream .return_value = {"stream" : []}
20852086
2086- # Messages with citationsContent using tagged union CitationLocation structure
2087+ # Messages with citationsContent using all tagged union CitationLocation types
20872088 messages = [
2088- {"role" : "user" , "content" : [{"text" : "Analyze this document " }]},
2089+ {"role" : "user" , "content" : [{"text" : "Analyze multiple sources " }]},
20892090 {
20902091 "role" : "assistant" ,
20912092 "content" : [
@@ -2104,8 +2105,34 @@ async def test_citations_content_preserves_tagged_union_structure(bedrock_client
21042105 "sourceContent" : [{"text" : "Vacation policy allows 15 days per year" }],
21052106 "title" : "Vacation Policy" ,
21062107 },
2108+ {
2109+ "location" : {"documentChunk" : {"documentIndex" : 1 , "start" : 5 , "end" : 8 }},
2110+ "sourceContent" : [{"text" : "Company culture emphasizes work-life balance" }],
2111+ "title" : "Culture Section" ,
2112+ },
2113+ {
2114+ "location" : {
2115+ "searchResultLocation" : {
2116+ "searchResultIndex" : 0 ,
2117+ "start" : 25 ,
2118+ "end" : 150 ,
2119+ }
2120+ },
2121+ "sourceContent" : [{"text" : "Search results show industry best practices" }],
2122+ "title" : "Search Results" ,
2123+ },
2124+ {
2125+ "location" : {
2126+ "web" : {
2127+ "url" : "https://example.com/hr-policies" ,
2128+ "domain" : "example.com" ,
2129+ }
2130+ },
2131+ "sourceContent" : [{"text" : "External HR policy guidelines" }],
2132+ "title" : "External Reference" ,
2133+ },
21072134 ],
2108- "content" : [{"text" : "Based on the document, employees receive comprehensive benefits." }],
2135+ "content" : [{"text" : "Based on multiple sources, the company offers comprehensive benefits." }],
21092136 }
21102137 }
21112138 ],
@@ -2123,7 +2150,7 @@ async def test_citations_content_preserves_tagged_union_structure(bedrock_client
21232150 formatted_messages = call_args ["messages" ]
21242151 citations_content = formatted_messages [1 ]["content" ][0 ]["citationsContent" ]
21252152
2126- # Verify the tagged union structure is preserved
2153+ # Verify the tagged union structure is preserved for all location types
21272154 expected_citations = [
21282155 {
21292156 "location" : {"documentChar" : {"documentIndex" : 0 , "start" : 150 , "end" : 300 }},
@@ -2135,6 +2162,32 @@ async def test_citations_content_preserves_tagged_union_structure(bedrock_client
21352162 "sourceContent" : [{"text" : "Vacation policy allows 15 days per year" }],
21362163 "title" : "Vacation Policy" ,
21372164 },
2165+ {
2166+ "location" : {"documentChunk" : {"documentIndex" : 1 , "start" : 5 , "end" : 8 }},
2167+ "sourceContent" : [{"text" : "Company culture emphasizes work-life balance" }],
2168+ "title" : "Culture Section" ,
2169+ },
2170+ {
2171+ "location" : {
2172+ "searchResultLocation" : {
2173+ "searchResultIndex" : 0 ,
2174+ "start" : 25 ,
2175+ "end" : 150 ,
2176+ }
2177+ },
2178+ "sourceContent" : [{"text" : "Search results show industry best practices" }],
2179+ "title" : "Search Results" ,
2180+ },
2181+ {
2182+ "location" : {
2183+ "web" : {
2184+ "url" : "https://example.com/hr-policies" ,
2185+ "domain" : "example.com" ,
2186+ }
2187+ },
2188+ "sourceContent" : [{"text" : "External HR policy guidelines" }],
2189+ "title" : "External Reference" ,
2190+ },
21382191 ]
21392192
21402193 assert citations_content ["citations" ] == expected_citations , (
0 commit comments