Skip to content

fix: insert cachePoint before non-PDF document blocks in _inject_cache_point()#2070

Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/cache-point-before-non-pdf-documents
Open

fix: insert cachePoint before non-PDF document blocks in _inject_cache_point()#2070
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/cache-point-before-non-pdf-documents

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Description

_inject_cache_point() always appended the cachePoint to the end of the last
user message's content array. When the last block was a non-PDF document
(md, docx, csv, xlsx, html, txt), Bedrock could not translate the sequence
to the Anthropic API format, raising ValidationException. PDF documents were
unaffected because Anthropic handles them natively.

The fix walks backwards from the end of the content array, skips any trailing
non-PDF document blocks, and inserts the cachePoint before them. All other
content types (text, images, tool results, PDF documents) behave exactly as
before.

Related Issues

Resolves #1966

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change?

  • I ran hatch run prepare

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 updated the documentation accordingly
  • 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.

…e_point()

_inject_cache_point() always appended the cachePoint to the end of the last
user message's content array. When the last block was a non-PDF document
(md, docx, csv, xlsx, html, txt), Bedrock could not translate the sequence
to the Anthropic API format, raising ValidationException because Anthropic
does not natively support non-PDF documents and the conversion path failed.
PDF documents were unaffected.

The fix walks backwards from the end of the content array, skipping trailing
non-PDF document blocks, and inserts the cachePoint before them. Existing
behavior is preserved for all other content types (text, images, tool results,
PDF documents).

Resolves strands-agents#1966
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.

cachePoint after non-PDF document blocks causes ValidationException on Bedrock ConverseStream

1 participant