mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* 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> |
||
|---|---|---|
| .. | ||
| arize | ||
| azure_storage | ||
| bitbucket | ||
| clickhouse | ||
| cloudzero | ||
| code_interpreter_interception | ||
| compression_interception | ||
| custom_logger_v2 | ||
| datadog | ||
| dotprompt | ||
| email_alerting | ||
| focus | ||
| gcs_bucket | ||
| gcs_pubsub | ||
| generic_api | ||
| gitlab | ||
| helicone | ||
| langfuse | ||
| lens | ||
| levo | ||
| litellm_agent | ||
| mavvrik_focus | ||
| newrelic | ||
| open_telemetry | ||
| opik | ||
| otel | ||
| pointfive | ||
| prompt_cache_alerts | ||
| s3_v2_golden | ||
| SlackAlerting | ||
| ternary | ||
| vantage | ||
| vector_store_integrations | ||
| websearch_interception | ||
| zerobus | ||
| __init__.py | ||
| conftest.py | ||
| rubrik_test_helpers.py | ||
| s3_v2_rust_support.py | ||
| test_agentops.py | ||
| test_anthropic_cache_control_hook.py | ||
| test_argilla.py | ||
| test_athina.py | ||
| test_azure_sentinel.py | ||
| test_braintrust_logging.py | ||
| test_braintrust_span_name.py | ||
| test_custom_callback_input.py | ||
| test_custom_guardrail.py | ||
| test_custom_guardrail_post_call_once.py | ||
| test_custom_guardrail_recursion.py | ||
| test_custom_logger.py | ||
| test_custom_prompt_management.py | ||
| test_customer_budget_webhook.py | ||
| test_deepeval.py | ||
| test_dynamodb.py | ||
| test_email_alerting.py | ||
| test_galileo.py | ||
| test_guardrail_logging_sync.py | ||
| test_helicone.py | ||
| test_humanloop.py | ||
| test_lago.py | ||
| test_langfuse.py | ||
| test_langfuse_otel.py | ||
| test_langsmith.py | ||
| test_langsmith_init.py | ||
| test_langtrace.py | ||
| test_lunary.py | ||
| test_mlflow.py | ||
| test_openmeter.py | ||
| test_opentelemetry.py | ||
| test_opentelemetry_dynamic_imports.py | ||
| test_opentelemetry_request_spans.py | ||
| test_opik_utils.py | ||
| test_otel_guardrail_violation_spans.py | ||
| test_otel_team_attributes_matrix.py | ||
| test_performance_alert_notifications.py | ||
| test_posthog.py | ||
| test_prefix_block_hashes.py | ||
| test_prometheus_api_promql_escape.py | ||
| test_prometheus_budget_metric_guard.py | ||
| test_prometheus_budget_metrics_db_lookups.py | ||
| test_prometheus_budget_metrics_timeout.py | ||
| test_prometheus_cache_metrics.py | ||
| test_prometheus_caller_identity.py | ||
| test_prometheus_carried_budget_state.py | ||
| test_prometheus_client_ip_user_agent.py | ||
| test_prometheus_custom_metadata_label_counts.py | ||
| test_prometheus_deployment_state_proxy_rejects.py | ||
| test_prometheus_end_user_cardinality.py | ||
| test_prometheus_input_sequence_length_label.py | ||
| test_prometheus_invalid_key_filtering.py | ||
| test_prometheus_labels.py | ||
| test_prometheus_mcp_tool_metrics.py | ||
| test_prometheus_media_generation_metrics.py | ||
| test_prometheus_metric_name_consistency.py | ||
| test_prometheus_metrics_endpoint.py | ||
| test_prometheus_missing_metrics.py | ||
| test_prometheus_none_metadata.py | ||
| test_prometheus_overhead_with_guardrails.py | ||
| test_prometheus_queue_guardrail_metrics.py | ||
| test_prometheus_rate_limit_labels.py | ||
| test_prometheus_remaining_tokens_router_fallback.py | ||
| test_prometheus_requested_model_cardinality.py | ||
| test_prometheus_series_cardinality.py | ||
| test_prometheus_service_tier_label.py | ||
| test_prometheus_services.py | ||
| test_prometheus_spend_capture_rate.py | ||
| test_prometheus_spend_logs_metadata.py | ||
| test_prometheus_stream_label.py | ||
| test_prometheus_token_detail_metrics.py | ||
| test_prometheus_user_team_metrics.py | ||
| test_prometheus_zero_cost_metric.py | ||
| test_prompt_layer.py | ||
| test_prompt_manager_ssti.py | ||
| test_responses_background_cost.py | ||
| test_rubrik.py | ||
| test_s3.py | ||
| test_s3_v2_native.py | ||
| test_s3_v2_rust.py | ||
| test_s3_v2_strip_writer.py | ||
| test_shadow_eval_logger.py | ||
| test_sqs.py | ||
| test_wandb.py | ||
| test_weave_otel.py | ||