mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* fix(guardrails): write rewritten tool_calls from the Generic Guardrail API back to the client The guardrail's response tool_calls were dropped at parse time and the /v1/messages output handler never applied them, so a post_call guardrail that masks tool-call arguments had no effect on any endpoint. The hook now parses tool_calls, matches them one to one with the calls it sent, keeps each call's own id and type, and forwards them. An empty array is no rewrite. A list of another length or a malformed entry is a guardrail error governed by fail_on_error. The Anthropic output handler writes the returned calls onto the tool_use blocks by position. * fix(guardrails): write tool-call rewrites back on multi-choice chat streams The ended-stream write-back grouped tool-call fragments by tool index alone, so it refused every stream with more than one choice. The pipeline then released the original chunks, undoing text redactions on n>1 streams as soon as a guardrail also rewrote a tool call. Fragments are now keyed by (choice index, tool index), the key stream_chunk_builder already uses, and the refusal is gone * fix(guardrails): drop safeguard verdicts and explanations for rewritten tool_use inputs The non-streaming /v1/messages write-back replaced a tool_use input but left the safeguard_results the classifier stamped on the original input, so an explanation could still quote the secret the guardrail masked. The response now keeps verdicts only for unchanged tool_use blocks and drops every explanation, the rule the ended-stream path already follows * fix(guardrails): keep BLOCKED verdicts when tool_calls are malformed, ignore non-list tool_calls on /v1/messages A Generic Guardrail API answer of action BLOCKED with a malformed tool_calls value raised a validation error before the BLOCKED check, so fail_on_error false let the request through. tool_calls is now parsed when it is written back, after the verdict. The /v1/messages output write-back read any returned tool_calls with the right length as calls, so a guardrail handing back a mapping (HiddenLayer's evaluation dict) failed the response. It now only reads a list, as the chat handler does. Also drops the added docstrings and the unrelated test reformatting * fix(guardrails): keep guardrail tool_call arguments out of validation errors A malformed tool_calls answer from the Generic Guardrail API raised a pydantic ValidationError that quoted the offending input, and the hook logs that message and returns it in the client's HTTP error, so tool arguments could leak through the error path. The adapter now hides input values in its errors |
||
|---|---|---|
| .. | ||
| guardrail_hooks | ||
| __init__.py | ||
| test_anthropic_sse.py | ||
| test_auto_router_compression.py | ||
| test_content_filter_path_traversal.py | ||
| test_content_utils.py | ||
| test_custom_code_security.py | ||
| test_deferred_guardrail_logging.py | ||
| test_endpoint_image_scan.py | ||
| test_guardrail_coverage.py | ||
| test_guardrail_endpoints.py | ||
| test_guardrail_helpers.py | ||
| test_guardrail_initializers.py | ||
| test_guardrail_load_balancing.py | ||
| test_guardrail_registry.py | ||
| test_init_guardrails.py | ||
| test_llm_as_a_judge.py | ||
| test_mcp_jwt_signer.py | ||
| test_pillar_guardrails.py | ||
| test_prompt_security_guardrails.py | ||
| test_qostodian_nexus_guardrail.py | ||
| test_usage_endpoints.py | ||
| test_usage_tracking.py | ||