litellm/tests/unit/llms/bedrock/files
zoveki 11cd3c3f7f
fix(bedrock): send guarded_text parts in system and assistant messages as Converse guardContent (#51776)
* fix(bedrock): send guarded_text parts in system and assistant messages as Converse guardContent

* fix(bedrock): drop guarded_text parts on the Nova invoke route under drop_params

* fix(bedrock): send guarded_text parts as text under drop_params when the request cannot carry guardContent

* fix(bedrock): trim a final guarded assistant turn and honor batch drop_params for guarded parts

Claude on Converse rejects a final assistant turn that ends in whitespace,
and the trim covered only text blocks, so a guarded_text prefill ending in
whitespace now answered 400. The trim now covers guardContent text too,
which also covers the drop_params text fallback that runs after it.

Nova batch records built their request without the record's drop_params,
so a guarded system part stayed guardContent, which Nova InvokeModel
rejects. The record's drop_params now reaches the transform.

The new Nova tests split a nested generator and gain type annotations.

* fix(bedrock): keep the full guardrail input check and reject malformed content parts

A guarded assistant or mid-conversation system part goes as text under guardrailConfig when no user turn is guarded, since guardContent there would narrow Bedrock's input check to that part. A system or guarded_text part whose text is not a string now gets a 400 instead of being dropped.

* fix(bedrock): keep the full guardrail input check when a guarded system message ends the request

A guarded system message after the last assistant turn or tool result became a trailing user turn that the guardrail auto-wrap then guarded alone, so Bedrock skipped the user's text. The rule now reads the trailing turns after the system conversion and leaves them unguarded when nothing else would be. A user guarded_text part whose text is not a string now gets litellm's 400 that names it.

* fix(bedrock): keep guarded parts guarded when tool history without tools gets guarded

With tool history and no tools param, litellm rewrites each tool result into a guarded user turn after the input check decision ran, so a guarded system part sent as text escaped the check. The decision now keeps the part guarded when that rewrite will guard a tool result.

* fix(bedrock): keep the full guardrail input check after an unanswered tool call without tools

* fix(bedrock): guard trailing turns only when a user turn is among them

A plain system message that ends a request after an assistant turn or a tool result
became a user turn, and the trailing guardrail wrap guarded it alone, so Bedrock
checked only the system text and a blocked word in an earlier user turn got through

* test(bedrock): cover a function result without tools keeping a guarded part guarded

* test(bedrock): expect the full input check for a guarded assistant part before a trailing system turn

A trailing system turn alone no longer gets the trailing guard wrap, so a guarded assistant part before it goes as
text whatever the system text holds, and Bedrock checks every message

* fix(bedrock): keep the full guardrail input check when tool history comes without tools

* fix(bedrock): keep guarded assistant text guarded when its tool calls turn into text

Without a tools param, an assistant turn with tool calls is flattened to text. When a guarded user turn makes the guardrail check only guarded blocks, that flattening also turned the assistant's guarded_text parts into plain text, so the guardrail skipped them. In that case keep those parts guarded and append the tool-call text as its own text part. Everywhere else the turn is flattened as before

* fix(bedrock): keep a user question before rewritten tool results in the guard wrap

With tool history and no tools param, litellm rewrites each tool result as a user turn. The trailing guard wrap stopped at the tool result, so a plain user question right before it went as plain text beside guarded blocks and its blocked word skipped the guardrail. Rewritten tool results now count in the trailing run, which matches the merge base

* fix(bedrock): keep guarding a trailing system message next to a caller-guarded user turn

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-16 19:11:35 -08:00
..
__init__.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
expected_bedrock_batch_completions.jsonl test(llms): migrate bedrock, baseten and base_llm batch tests to tests/unit 2026-09-20 07:51:50 +00:00
expected_bedrock_batch_embeddings.jsonl test(llms): migrate bedrock, baseten and base_llm batch tests to tests/unit 2026-09-20 07:51:50 +00:00
input_batch_completions.jsonl test(llms): migrate bedrock, baseten and base_llm batch tests to tests/unit 2026-09-20 07:51:50 +00:00
input_batch_embeddings.jsonl test(llms): migrate bedrock, baseten and base_llm batch tests to tests/unit 2026-09-20 07:51:50 +00:00
test_bedrock_files_handler.py feat(proxy)!: only let clients pick S3 buckets the admin allowed (#47496) 2026-11-06 02:50:15 +00:00
test_bedrock_files_transformation.py fix(bedrock): send guarded_text parts in system and assistant messages as Converse guardContent (#51776) 2026-11-16 19:11:35 -08:00