litellm/tests/test_litellm/llms/anthropic/chat
yucheng-berri 76b0b10908
fix(guardrails): add /v1/messages support for Straiker plugin (#34548)
* fix(guardrails): add /v1/messages support for Straiker plugin

- Pass prepared response data to Anthropic Messages streaming post-call hooks (litellm/llms/anthropic/chat/guardrail_translation/handler.py)
- Normalize Straiker request, tool, finish-reason, and mode fields across Chat Completions, Messages, and Responses APIs

* fix(guardrails): gate cross-surface message resolution and cover streaming request data

Resolve request messages only for surfaces that have a mapped translation
handler. The unguarded fallback tried every registered handler in turn, which
raised AttributeError out of the guardrail's error handling on list-shaped
`input` bodies, and synthesized a chat message that was never sent for bodies
it happened to parse.

Prepare request data on the mid-stream Anthropic branch as well, matching the
terminal branch and the OpenAI handler, so guardrails that scan before
end-of-stream still receive identity metadata.

Read usage from Anthropic dict responses so non-streaming /v1/messages reports
token counts instead of null.

Add regression coverage for the streaming request data on both the terminal and
mid-stream branches; reverting either now fails.

---------

Co-authored-by: cs-mehta <chandra@straiker.ai>
2026-07-24 17:13:11 -07:00
..
guardrail_translation fix(guardrails): add /v1/messages support for Straiker plugin (#34548) 2026-07-24 17:13:11 -07:00
conftest.py refactor: remove unnecessary comments from #27074 2026-05-04 19:34:56 +00:00
test_anthropic_chat_handler.py chore: litellm oss staging (#31185) 2026-06-26 09:17:44 -07:00
test_anthropic_chat_transformation.py fix(anthropic): use native output capability (#33235) 2026-07-14 14:23:49 -07:00
test_code_interpreter_results_extraction.py fix: streaming container_id and consistent Pydantic types in output 2026-03-18 12:37:13 +01:00