Skip to content

Pass through cachePoint and other Bedrock-native content blocks#2078

Open
debu-sinha wants to merge 1 commit into567-labs:mainfrom
debu-sinha:fix/bedrock-cachepoint-passthrough
Open

Pass through cachePoint and other Bedrock-native content blocks#2078
debu-sinha wants to merge 1 commit into567-labs:mainfrom
debu-sinha:fix/bedrock-cachepoint-passthrough

Conversation

@debu-sinha
Copy link

Fixes #1954

What changed

_to_bedrock_content_items was raising ValueError for any Bedrock-native dict content block it didn't explicitly recognize. This broke caching functionality (cachePoint) introduced in Bedrock's Converse API, and would also break guardContent, audio, video, and any other content block types AWS adds in the future.

The fix replaces the ValueError with a pass-through for unrecognized Bedrock-native dicts (dicts without a "type" key, which distinguishes them from OpenAI-style parts). The Bedrock API validates content blocks on its end, so instructor doesn't need to maintain a hardcoded allowlist that falls behind API changes.

Changes

  • instructor/providers/bedrock/utils.py: Replace ValueError with pass-through for unrecognized Bedrock-native content blocks. Updated docstring to document cachePoint and other supported types.
  • tests/llm/test_bedrock/test_bedrock_native_passthrough.py: Added regression tests for cachePoint (with and without TTL), guardContent, audio, video, and mixed content with cache points matching the exact reproduction from [bedrock] - Bedrock caching broken in v1.13.0 - ValueError with cachePoint dict content #1954.

Testing

All 32 bedrock tests pass (11 new, 21 existing):

tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_cachepoint_passthrough PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_cachepoint_with_ttl PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_guard_content_passthrough PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_content_block_passthrough[cachePoint] PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_content_block_passthrough[guardContent] PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_content_block_passthrough[video] PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_bedrock_native_content_block_passthrough[audio] PASSED
tests/llm/test_bedrock/test_bedrock_native_passthrough.py::test_mixed_content_with_cachepoint PASSED

Also verified against the exact reproduction code from #1954 -- the ValueError is gone and cachePoint dicts pass through correctly.

Fixes 567-labs#1954. The _to_bedrock_content_items function was raising
ValueError for unrecognized Bedrock-native dict content blocks
like cachePoint, guardContent, audio, and video. These are valid
Bedrock Converse API content types that should be passed through
to the API unchanged, just like text, image, and document blocks.

Instead of maintaining an explicit allowlist that breaks whenever
AWS adds new content types, pass through any dict that does not
match the OpenAI-style format (no "type" key). The Bedrock API
itself validates content blocks, so instructor does not need to
be the gatekeeper here.

Signed-off-by: debu-sinha <debusinha2009@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bedrock] - Bedrock caching broken in v1.13.0 - ValueError with cachePoint dict content

1 participant