litellm/tests/test_litellm/llms/bedrock
tin-berri e50a42051c
fix(websearch): restore snippet text in native web_search_tool_result blocks (LIT-5315) (#36228)
* fix(websearch): restore snippet text in native web_search_tool_result blocks (LIT-5315)

The build_web_search_tool_result_block method copied url/title/page_age but
hardcoded encrypted_content to empty string, never reading SearchResult.snippet.
This left every native block content-free, forcing clients to web_fetch each
result to recover evidence—the reported symptom.

The Anthropic spec carries page text only in encrypted_content (an opaque
server-issued blob we cannot mint), so snippet is emitted as an additive key
alongside the spec fields. encrypted_content stays empty rather than holding
plaintext, which would assert encryption semantics that don't hold.

The anthropic SDK's BaseModel sets extra='allow', so the additive snippet key
survives SDK parsing. litellm has no typed model for web_search_result at all,
so nothing drops it internally. Turn-2 replay behavior is unaffected: the
empty encrypted_content already exists today.

Tests:
- Updated test_shape_with_results to assert snippet present
- Added test_snippet_carried_for_every_result to cover multi-result ordering
- Added test_missing_snippet_degrades_to_empty_string for edge case
- Mutation check: reverting source-only yields 3 test failures, restored to 117 passed

Fixes: LIT-5315
Co-Authored-By: Claude <noreply@anthropic.com>

* fix(websearch): make synthesized web_search blocks replayable by native clients

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(websearch): flatten a resultless replayed search block so Bedrock accepts the next turn

The flatten added for LIT-5315 bails when the replayed web_search_tool_result
carries an empty content list, but that is exactly what the interceptor emits
when a search legitimately returns nothing and when a search raises. The block
survived into the outbound body, Bedrock rejected the tag, and the conversation
died on the following turn just as it did before the flatten existed.

An empty content list has no encrypted_content to respect and no evidence to
preserve, so it flattens safely, and its paired server_tool_use goes with it.
The rendered text now says so explicitly rather than emitting a bare header.

Adds the multi-turn replay coverage that existed nowhere: the outbound Bedrock
invoke body is asserted free of both block types, parametrized over the
results-present and resultless cases, and built from the interceptor's own
builder so the fixture cannot drift from what it emits.

Resolves LIT-5320

* test(websearch): pin flatten idempotency for the agentic-loop re-entry

The agentic loop re-enters the same /v1/messages entry point for its follow-up
call and hands it the original client history, so the flatten runs again over
already-flattened messages once per iteration. Bedrock always takes that path,
since its config reports web search as natively handled and the short-circuit
is skipped.

A pass that appended the rendered text instead of replacing the block would
duplicate the evidence on every iteration and re-ship the unsupported tag, and
no existing single-pass test sees it. Mutation checked: keeping the original
block alongside the rendered text fails this test on its own.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Yassin Kortam <yassin@berri.ai>
2026-08-07 17:28:55 -07:00
..
batches fix(bedrock): pass SSE-KMS key through to the batch input-file S3 upload 2026-07-29 22:09:49 +00:00
chat fix(bedrock): drop conflicting tool_choice.type when toolConfig.toolChoice is set 2026-08-04 03:50:33 +00:00
count_tokens Litellm oss 090626 (#30021) 2026-06-10 10:34:07 -07:00
embed fix(bedrock/cohere): send embedding_types as JSON array, not string (#28172) 2026-05-18 12:16:20 -07:00
files test(bedrock): cover the batch record classifier fallbacks and pin metadata handling 2026-08-06 22:35:56 -07:00
image style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
image_edit Litellm ishaan april1 try2 (#25110) 2026-04-03 14:57:44 -07:00
invoke_agent fix: cover provider path traversal variants 2026-04-29 22:29:09 -07:00
messages/invoke_transformations fix(websearch): restore snippet text in native web_search_tool_result blocks (LIT-5315) (#36228) 2026-08-07 17:28:55 -07:00
passthrough feat(proxy): enforce key/team guardrails on bedrock passthrough routes (#30194) 2026-06-12 07:23:29 -07:00
realtime fix(bedrock): emit Nova Sonic realtime session.created on connect and session.updated on session.update (#34133) 2026-07-22 06:15:37 +00:00
rerank style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
vector_stores fix: encode upstream URL path identifiers 2026-04-29 22:02:39 -07:00
__init__.py test(batches): add 1:1 test file scaffold for batches component paths (#30529) 2026-06-29 09:22:58 +05:30
test_anthropic_beta_support.py fix(bedrock): allowlist Bedrock Invoke body fields and filter all anthropic-beta values 2026-04-21 11:26:15 -07:00
test_base_aws_llm.py fix(bedrock): cache AssumeRole credentials per attributed identity (#35467) 2026-08-01 13:54:42 -07:00
test_bedrock_common_utils.py fix(bedrock): honor ttl for tool_config cache injection points (#31929) 2026-07-02 16:30:06 -07:00
test_bedrock_ssl_verify.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_claude_platform_provider.py Litellm OSS Staging 010626 (#29422) 2026-06-01 21:42:51 -07:00
test_converse_context_management.py feat(context_management): compact_20260112 polyfill for non-Anthropic providers (#28868) 2026-05-30 09:20:05 -07:00
test_cross_region_inference_profile_mapping.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_mantle.py fix(bedrock-mantle): backfill usage on non-streaming /v1/messages responses 2026-07-23 23:37:40 +00:00
test_web_identity_session_policy.py fix(bedrock): grant bedrock:CountTokens in OIDC session policy (#33145) 2026-08-05 14:55:46 -07:00