Skip to content

test(llms): add bedrock content and usage contract tests - #9096

Merged
Lorenze Jay (lorenzejay) merged 3 commits into
crewAIInc:mainfrom
bballhaus:test/bedrock-content-usage-contract
Nov 10, 2026
Merged

Lorenze Jay (lorenzejay) merged 3 commits into
crewAIInc:mainfrom
bballhaus:test/bedrock-content-usage-contract

Conversation

@bballhaus

@bballhaus Brooke Ballhaus (bballhaus) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Related issue

Fixes #8128

Summary

Test-only. Adds lib/crewai/tests/llms/bedrock/test_bedrock_content_usage_contract.py, Bedrock's side of the shared native-provider content and usage contract, driven by fake Converse responses (no AWS credentials, no network).

Verification

Additional context

Assumptions I made where Bedrock differs from the shared suites. Can you confirm these, or tell me if either should be treated as a defect instead?

  1. Bedrock's LLMCallCompletedEvent.usage is the raw Converse dict (inputTokens / outputTokens / totalTokens), while test(llms): shared tool-call, streaming, usage and failure contract for OpenAI and Anthropic #8062 asserts usage["total_tokens"] for OpenAI and Anthropic. I treated this as Bedrock-specific and recorded it in the module docstring without asserting either shape.
  2. A Converse response with no content blocks returns an apology string instead of "" (the shared rule in test: shared plain-text contract tests for OpenAI and Anthropic providers #8037). Same treatment: recorded, not asserted.

This PR was written with AI assistance (Claude Code); I reviewed and can explain every line. Per CONTRIBUTING.md it needs the llm-generated label, which I can't apply as a contributor. Could a maintainer add it? Thanks!


Note

Low Risk
Test-only change with no production code paths modified; risk is limited to CI behavior (including expected xfails).

Overview
Adds test_bedrock_content_usage_contract.py, a standalone Bedrock adapter for the shared native-provider content/usage contract (issue #8128), using fake Converse recorders so tests never hit AWS.

The suite asserts message shaping (verbatim strings, Converse text/image blocks, None not serialized as "None", system text on the top-level system param, no in-place mutation of caller messages) and sync/async parity (call vs acall on the aiobotocore path, identical requests, token usage accumulated in get_token_usage_summary()).

Four strict xfail tests document known gaps (#7920 system/parts handling, #9095 OpenAI-style parts not converted) without changing Bedrock runtime code.

Reviewed by Cursor Bugbot for commit 2c7f46a. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 45 commits after the last Strix review (87e5fd6). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: Adds a Bedrock-specific pytest contract suite that drives fake Converse responses to assert message content formatting, sync/async parity, and token usage accounting for `BedrockCompletion`.

Review summary

This change adds only a new pytest module under lib/crewai/tests/llms/bedrock/ — no production, configuration, or dependency files are touched. The file builds fake Converse responses and monkeypatches the Bedrock client, so it exercises no network, credentials, subprocess, filesystem, deserialization, or template surface, and introduces no attacker-reachable sink. The strict xfail marks merely record pre-existing content-formatting behavior in the Bedrock provider (list/None system content, and OpenAI-style parts forwarded unconverted); those are correctness defects tracked in #7920 and #9095, not security issues, and nothing in this PR makes them exploitable. No security vulnerabilities found in the changed code.

Review 1 on this PR · 87e5fd6 · requested Nov 5 03:25 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

@bballhaus

Copy link
Copy Markdown
Contributor Author

Hi Lorenze Jay (@lorenzejay), this is ready for a look when you have time. It’s test-only for crewAIInc/crewAI#8128. Could you approve the CI run and add the llm-generated label? There are two Bedrock-specific assumptions under “Additional context” I’d like you to confirm. Thanks!

@lorenzejay
Lorenze Jay (lorenzejay) merged commit ed558c5 into crewAIInc:main Nov 10, 2026
11 checks passed
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.

[FEATURE] Extend shared native LLM content and usage contracts to Bedrock

2 participants