litellm/enterprise/enterprise_hooks
yucheng-berri d4a32771fd
fix(proxy): scan batch records with the content hooks that are not guardrails (#37786)
* fix(proxy): scan batch records with the content hooks that are not guardrails

Guardrails were made to run on batch uploads by scanning each record through the pre-call hook
with the walk limited to guardrails. That limit exists because the same branch carries the rate
limiters and budget accounting, which must count an upload once rather than once per line. It
also excluded every enforcement hook written as a plain CustomLogger, so prompt-injection
detection, Azure content safety, banned keywords and the blocked-user check never saw a batch
record at all. Content that is a hard 400 online reached the provider verbatim through batch.

A CustomLogger now declares whether its pre-call hook judges the payload or merely counts the
request. The four that judge it opt in, the walk admits them, and both short-circuits learn
about them, including the one that decides whether the file is streamed off disk in the first
place: a proxy configured only with one of these hooks was skipping the scan entirely. Nothing
that counts a request is marked, so an upload still costs one slot and one budget check.

* refactor(proxy): drop the per-hook comment the attribute contract already states

* test(proxy): make the classification a ledger, and pin the wiring with a real hook

The classification test listed the two non-enterprise hooks by hand, so unmarking either
enterprise one changed nothing and the mutation matrix passed with both surviving. It now walks
the hook registries and fails on any pre-call CustomLogger that is on neither side, which also
gives the flag the forcing function it lacked: an enforcement hook added later would otherwise
default to off and silently skip batch records, which is the bug being fixed here.

Nothing exercised the path the bug actually lived on either, since every test raised its own
exception rather than a real hook's. One test now drives the shipped prompt-injection hook
through the scan, which pins the part no synthetic exception reaches: a chained exception reads
as a failure to judge, so refactoring any of these hooks to `raise ... from` would turn every
per-record drop into an aborted upload.

Also records why a hook that rewrites the payload for routing stays unmarked, and that only the
leaf class is consulted.

* test(proxy): set the callback list through monkeypatch rather than writing the global
2026-08-21 11:20:23 -07:00
..
__init__.py Add using managed vector store creds for vector store files endpoint 2026-02-13 10:33:49 +05:30
aporia_ai.py feat(audio_transcriptions/): calculate duration of audio file for cost calculation + feat (image_generations): cost tracking accuracy improved with output_format, quality, size values fixed per openai model 2025-11-08 16:24:31 -08:00
banned_keywords.py fix(proxy): scan batch records with the content hooks that are not guardrails (#37786) 2026-08-21 11:20:23 -07:00
blocked_user_list.py fix(proxy): scan batch records with the content hooks that are not guardrails (#37786) 2026-08-21 11:20:23 -07:00
google_text_moderation.py fix(guardrails): close mixed-list gap, drop dead code, rename helper 2026-05-01 04:10:04 +00:00
openai_moderation.py fix(guardrails): close mixed-list gap, drop dead code, rename helper 2026-05-01 04:10:04 +00:00