* 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>