Repository navigation
Conversation
Bedrock Converse rejects a cachePoint that directly follows a txt, csv, md, html, docx or xlsx document block. Move it ahead of those documents, and drop it when nothing cacheable precedes them. Fixes BerriAI#50923
habonlaci
marked this pull request as ready for review
November 10, 2026 15:57
Contributor
PR overviewNo security issues were found in this pull request. Reviews
|
Contributor
Author
Contributor
Author
|
bugbot run |
Contributor
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d31d23a. Configure here.
This branch has not been deployed
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.
Handwritten 1-3 sentence description
Bedrock Converse rejects a request with "Cache point cannot be inserted after the preceding content block" when a cache point directly follows a non-PDF document block such as txt or csv. This hapens whenever the last content block of a message is such a file and prompt caching puts a cache point on it. The fix moves the cache point in front of those documents, or drops it when nothing cacheable comes before them.
Details
TLDR
Problem this solves:
cache_controlon a txt, csv, md, html, docx or xlsx file fails tooHow it solves it:
User Flow
Before: a chat app user attaches a text file after their question and the request to a Bedrock Claude model fails
enable_anthropic_prompt_caching: trueinlitellm_settingstext/plainfile part, or the same on /v1/responses withinput_textandinput_fileCache point cannot be inserted after the preceding content block for this modelAfter: the same request returns a completion
enable_anthropic_prompt_caching: trueinlitellm_settingstext/plainfile partRelevant issues
Fixes #50923
Related
enable_anthropic_prompt_caching, which is how a cache point lands on a file the client never markedinput_fileparts reach the same codePre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live calls to Bedrock on 2026-11-10 through a local proxy, once from the merge base and once from the tip. The requests are synthetic and each one puts
cache_controlon a file that is the last content part.Shared setup
config.yamlEnv vars set:
AWS_PROFILE,AWS_REGION_NAME,LITELLM_MASTER_KEYProxy start, with
PYTHONPATHpointing at the checkout under testRequest, one per case with the matching body file
Request bodies
txt-last.json{ "model": "claude", "max_tokens": 32, "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Summarize the attached file in one sentence." }, { "type": "file", "file": { "file_data": "data:text/plain;base64,UXVhcnRlcmx5IG5vdGVzLiBSZXZlbnVlIHdlbnQgdXAgYnkgZm91ciBwZXJjZW50Lgo=" }, "cache_control": { "type": "ephemeral" } } ] } ] }csv-last.jsonis the same withfile_dataset topdf-last.jsonis the same withfile_dataset toBefore (7bcc462)
txt file last
txt-last.json400 litellm.BadRequestError: BedrockException - {"message":"Cache point cannot be inserted after the preceding content block for this model. Please remove the invalid cache point and try again."}csv file last
csv-last.jsonpdf file last
pdf-last.json200, usageprompt_tokens: 1609, completion_tokens: 14After (d31d23a)
txt file last
txt-last.json200, usageprompt_tokens: 91, completion_tokens: 13csv file last
csv-last.json200, usageprompt_tokens: 92, completion_tokens: 32pdf file last
pdf-last.json200, usageprompt_tokens: 1609, completion_tokens: 13Unit tests,
uv run pytest tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py -k cache_point_never_follows -q, give12 failed, 4 passedon 7bcc462 with only the new tests applied and16 passedon d31d23a. The whole file gives705 passed.Type
🐛 Bug Fix
Caveats (if any)
Medium
docandxlswere not tried live and are assumed to behave likedocxandxlsxLow
Final Attestation
Note
Medium Risk
Touches Bedrock Converse prompt assembly and cache breakpoint placement; behavior changes for cached requests with file attachments but is narrowly scoped with thorough tests.
Overview
Fixes Bedrock Converse 400 errors when prompt caching places a
cachePointimmediately after a non-PDF document (txt, csv, etc.).During Bedrock message translation, a new post-processing step reorders or drops
cachePointblocks: they move before trailing non-PDF documents when cacheable content exists earlier, are omitted when only documents lead the message, and stay unchanged after PDFs and plain text. The same logic runs on sync and async Converse message builders.New parametrized unit tests cover mixed file/text/caching layouts for both code paths.
Reviewed by Cursor Bugbot for commit d31d23a. Bugbot is set up for automated code reviews on this repo. Configure here.