litellm/tests/unit/llms/anthropic
jesus-berri 763c54c593
fix(guardrails): write rewritten tool_calls from the Generic Guardrail API back to the client (#50413)
* 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
2026-11-18 15:25:29 -08:00
..
batches feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
chat fix(guardrails): write rewritten tool_calls from the Generic Guardrail API back to the client (#50413) 2026-11-18 15:25:29 -08:00
files chore(typing): clear 670 basedpyright Any errors by validating provider payloads at the boundary (#45388) 2026-10-13 15:35:23 -07:00
messages feat(auth): read teams, team memberships and organizations through rust repositories (#52176) 2026-11-18 22:32:05 +00:00
pass_through refactor(anthropic): rename llms/anthropic/pass_through to llms/anthropic/messages (#48510) 2026-10-27 10:08:25 -07:00
__init__.py test(unit): add package markers to migrated unit test directories 2026-09-20 11:53:14 +00:00
anthropic_docs_refusal.py fix(anthropic): keep refusal stop_reason and stop_details on the logged response (#46104) 2026-10-14 14:42:49 -07:00
test_anthropic_common_utils.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_anthropic_count_tokens_transformation.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_anthropic_files_and_batches.py feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
test_anthropic_output_format_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_prompt_cache_prediction.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_anthropic_prompt_cache_pricing.py refactor(anthropic): move prompt cache pricing helper out of the proxy package (#45753) 2026-10-10 20:32:34 +00:00
test_anthropic_reasoning_effort.py fix(anthropic): disable optional default thinking for reasoning effort none (#50541) 2026-11-07 12:51:37 -08:00
test_anthropic_schema_filter.py fix(bedrock): use native structured output on Haiku 5.5 and Sonnet 5.5, and fix Fable 5 and Sonnet 4.6 schema 400s (#46870) 2026-10-16 20:57:23 -07:00
test_anthropic_structured_output.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_anthropic_wif.py fix(anthropic): exchange Google identity tokens again on refresh and read oidc/ references out of ANTHROPIC_IDENTITY_TOKEN (#50583) 2026-11-07 16:48:48 -08:00
test_azure_ai_cache_pricing.py test: move tests/test_litellm/llms into tests/unit/llms (#43191) 2026-09-25 12:43:23 -07:00
test_cost_calculation_dict_safety.py feat(anthropic): workload identity federation and pluggable identity sources (#44448) 2026-10-03 17:08:30 -07:00
test_count_tokens_oauth.py fix(count_tokens): count a history that carries a compaction block (#44784) 2026-10-30 00:11:55 -07:00
test_message_sanitization.py fix(bedrock): stop the prefill 400 when the last user message is empty (#50701) 2026-11-18 03:44:11 +00:00
test_messages_http_error_retry_cases.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00