litellm/tests/unit/llms/openai
chaznm 6c78e4c91d
fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169)
* fix(guardrails)!: close gaps in bedrock tool call and tool description scans

A tool call the bedrock policy masks in a model response now blocks with a 400 and is logged as guardrail_intervened, on the checks path too. In the request, a masked argument value is written back in the shape the caller sent it, a JSON string stays a JSON string and a dict stays a dict, and a mask on a tool name or argument key blocks instead

Each tool call is sent as separate text blocks, its name, every argument key and every string or number value, in one ApplyGuardrail call for all tool calls. The OUTPUT scan sends no grounding source. The text scan and the tool call scan run concurrently, each logs its own entry, and the text error is raised first

Gemini functionCall parts are now scanned in the request, the response and the stream. Tool calls use the incremental scan cache under their own scope, so a scanned message text no longer marks a tool call as scanned. scan_only_tool_results no longer turns off scan_tool_calls_as_text or scan_tool_descriptions_as_text

scan_tool_descriptions_as_text now scans on logging_only guardrails whose scope covers the request. Under disable_exception_on_block the response carries no tool call content, and arguments nested too deep to scan are logged as guardrail_intervened before the request is blocked

BREAKING CHANGE: creating or updating a guardrail through the API with scan_tool_descriptions_as_text set and a mode that never scans the request is now rejected, with a 400 on create and a 422 on update. At config load the setting is logged as an error and ignored

* fix(guardrails): reject a guardrail PATCH whose tool description scan never runs

* fix(guardrails): scan escaped and streamed tool call arguments, keep failed scans out of the cache

A tool call whose arguments are a JSON string is now decoded before the scan, and a mask goes back as an encoded string.
Gemini partialArgs parts are joined per JSON path before the scan, and a request rewrite of a joined call is rejected.
A Bedrock reply that carries an embedded error no longer marks tool calls as scanned.
Chat completions rejects an empty tool call list when the request carries server or legacy calls

* fix(guardrails): keep the documented 400 for masked tool calls and scan tool calls before text

A masked tool call that cannot go forward answers the same 400 as masked
text again, with bedrock_guardrail_response listing each masked block.
Bedrock scans tool calls before text, so a block skips the billed text
scan, and a tool call nested too deep answers 400 on every setting.
Logging-only scans run one after another in the caller's context, so
each logs its entry in a fixed order.

* fix(guardrails): log message text when a logging-only tool call scan blocks, refuse unwritable Responses tool call rewrites

A logging-only Bedrock guardrail now still scans and logs the message text when
its tool call scan raises, so the spend log shows every scan it ran.

Responses history tool call rewrites that cannot be written back (an item that
is not a dict, or returned arguments that are not a string) now fail closed with
the unappliable-rewrite error instead of forwarding the call unmasked.

* fix(guardrails): scan each tool call key with its value and write back masked Gemini partialArgs

Bedrock now gets one `key: value` block per scalar argument instead of separate key and value blocks, so PII
filters that need the key as context (PASSWORD, AGE) find the value again and the mask maps back to the value.

A guardrail on both pre_call and logging_only no longer runs the message scan after a blocked tool call in
pre_call. Only the logging hook runs it.

Masked string partialArgs in a Gemini history call are written back into the parts instead of failing the
request, and a part with its own name or args starts a new call even after willContinue.

* fix(gemini): write a masked number in a streamed tool call's history back as a string

* test(guardrails): type the apply_guardrail overrides of two logging-only test doubles

* fix(gemini): keep only the masked string in a streamed tool call part that mixes key cases

* fix(gemini): group partialArgs by path in one pass

Scanning or writing back a streamed Gemini call walked every partialArgs part once per JSON path, so a call with thousands of paths blocked the event loop for seconds

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 06:56:15 +00:00
..
chat fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
completion fix(openai): relay param and plain message from OpenAI-compatible backend errors (#53217) 2026-11-20 15:53:54 -08:00
decisions fix(decisions): match OpenAI format answers to questions by name (#52597) 2026-11-18 12:55:45 -08:00
embeddings fix(gemini): support explicit text in embedding inputs (#53135) 2026-11-20 11:05:11 -08:00
evals fix(llms): join api_base and route with one shared helper (#47535) 2026-10-21 06:59:32 +00:00
image_generation refactor(images): remove dall-e-2 and dall-e-3 code paths (#48703) 2026-10-28 17:48:09 -07:00
image_variations fix(openai): keep the upstream error body on e.response for OpenAI and Azure errors (#49079) 2026-10-29 23:30:02 -07:00
live feat(realtime)!: serve GPT-Live over WebRTC with sideband attach, and bill WebRTC calls from a proxy sideband (#53282) 2026-11-21 22:49:26 -08:00
realtime feat(realtime)!: support latest OpenAI audio models (#35600) 2026-11-03 07:27:52 +00:00
responses fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
speech test: add package initializers to migrated unit test directories 2026-09-20 11:52:07 +00:00
transcriptions test(groq): tell cost lookups the Whisper row changed in the catalog rate test (#54252) 2026-11-24 21:10:12 +00:00
vector_store_files fix(proxy)!: return provider-matching 4xx for the LIT-8062 status code follow-ups (#45537) 2026-10-13 11:42:39 -07:00
vector_stores test: add package initializers to migrated unit test directories 2026-09-20 11:52:07 +00:00
videos feat(videos): add first-class OpenRouter video request fields (#50319) 2026-11-06 16:50:48 -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
test_cost_calculation.py feat(fal_ai): bill fal video clips by duration and resolution (#51679) 2026-11-13 12:55:55 -08:00
test_data_residency.py feat(openai): bill gov.api.openai.com FedRAMP endpoint with 1.1x uplift (#49951) 2026-11-04 08:57:42 -08:00
test_gpt_reasoning_transformation.py fix(llms): treat chat-latest and gpt-chat-latest as gpt-5 family models (#51151) 2026-11-24 04:02:51 -08:00
test_is_model_gpt_5_model.py fix(llms): treat chat-latest and gpt-chat-latest as gpt-5 family models (#51151) 2026-11-24 04:02:51 -08:00
test_o_series_transformation.py fix(openai): drop or refuse an o-series reasoning_effort level the model map turns off (#54066) 2026-11-24 06:42:03 -08:00
test_openai.py fix(openai): preserve omitted headers for chat and embeddings (#53132) 2026-11-20 10:29:22 -08:00
test_openai_audio_speech.py fix(cost): bill OpenAI token-priced aac and flac speech on the length of the returned audio (#53308) 2026-11-21 19:53:23 +00:00
test_openai_authentication_error.py test: migrate local_testing SDK and provider tests out of build_and_test (#45760) 2026-10-10 23:14:25 +00:00
test_openai_common_utils.py fix(openai): relay provider error codes, types, and Responses params from OpenAI-compatible backends (#51809) 2026-11-24 02:23:00 +00:00
test_openai_empty_response.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00
test_openai_file_content_streaming.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_openai_image_edit_transformation.py fix(images): send image_edit markup as a multipart file part (#53815) 2026-11-25 04:14:57 +00:00
test_openai_workload_identity.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_organization_costs.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_use_chat_completions_api_no_leak.py fix(openai): send chat completions through client.post so the SDK's per-message param transform stops holding the event loop (#46967) 2026-10-16 18:06:01 -07:00