Skip to content

Conversation

@danilop
Copy link

@danilop danilop commented Dec 16, 2025

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 CitationLocation to be a tagged union with exactly one wrapper key (documentChar, documentPage, or documentChunk). The previous implementation was flattening the structure, causing validation errors:

botocore.exceptions.ParamValidationError: Must set one of the following keys 
for tagged union structure: web, documentChar, documentPage, documentChunk, searchResultLocation

Solution:

  • Refactored citation type definitions to use *Inner types + wrapper types for proper tagged union modeling
  • Added _format_citation_location helper method to preserve the union structure when filtering
  • Added comprehensive tests for all document-based citation location types

BREAKING CHANGE: CitationLocation types now use wrapper structure (e.g., {"documentChar": {"documentIndex": 0, ...}}) instead of flat structure. This matches the actual Bedrock API specification and fixes the runtime error.

Related Issues

Fixes #1323

Type of Change

Bug fix (breaking - but the previous behavior was incorrect and caused runtime errors)

Testing

  • I ran hatch run prepare (1615 tests pass)
  • Tests for documentChar, documentPage, documentChunk location types
  • Tests for field filtering and unknown location types

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The Bedrock API requires CitationLocation to be a tagged union with
exactly one wrapper key (documentChar, documentPage, or documentChunk).

Changes:
- Refactor citation type definitions to use Inner types + wrapper types
  for proper tagged union modeling
- Add _format_citation_location helper method to preserve union structure
- Add tests for all document-based citation location types

BREAKING CHANGE: CitationLocation types now use wrapper structure
(e.g., {'documentChar': {'documentIndex': 0, ...}}) instead of flat
structure. This matches the actual Bedrock API specification.

Fixes strands-agents#1323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bedrock Runtime API CitationLocation Tagged Union Structure Error

1 participant