litellm/tests/unit/caching
joshua-berri 24b046c1cd
fix(gemini): support explicit text in embedding inputs (#53135)
* fix(gemini): accept text blocks in embedding input and answer 400 for unparseable media

Gemini and Vertex gemini-embedding inputs now take {"type": "text", "text": ...}
elements, sent as text parts without prefix detection or a Files API lookup and
counted as text for usage and the cache message limit. A bare data: or gs://
string whose media type cannot be parsed raises BadRequestError (400) instead of
surfacing as a retryable APIConnectionError (500).

* fix(gemini): validate text blocks before file lookups and keep cache item counting total

Malformed text blocks now answer 400 before any Files API lookup in the same
request. The cache message count compares the item type explicitly, so an
unhashable type value counts as a conversation item as before instead of raising.
Adds regression cases for empty text, drop_params with a non-string text, and
plain-text token counting for flat, grouped and mixed inputs.

* refactor(caching): use tuple membership for embedding block types

* test(gemini): cover image-only usage attribution for bare media strings

* fix(guardrails): scan and rewrite text blocks in embedding input

Embedding input that carries {"type": "text"} elements, first, after a string
or inside a group, now sends every string and text block text to the guardrail
in one call and writes the results back in place, keeping block keys, file blocks
and groups. A rewrite with the wrong number of texts fails closed through the
existing unappliable rewrite error. Inputs without text blocks keep their current
handling.

* refactor(guardrails): type the embedding list guardrail path as one flow

Folds the text block and plain string list paths back into _process_list_input,
typing the input as Sequence[object] and checking model is a string before
forwarding it, so no new helper takes a bare dict. A string-first list that holds
non-string items now scans its strings and keeps the other items instead of
handing them to the guardrail as texts. Adds regression cases for empty text,
malformed text blocks, file blocks after a string and plain string list counts.

* fix(guardrails): limit the embedding text block path to inputs that carry text blocks

Only an input holding a text block goes through slot extraction, the count check
and the in-place rewrite. Every other list keeps the baseline flow, handing the
raw input to the guardrail and writing its texts back as returned, with the same
model forwarding.

* test(guardrails): type request_data on the embedding guardrail test doubles

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-20 11:05:11 -08:00
..
__init__.py ci: move caching, proxy-extras, gateway and enterprise tests into tests/unit and run them from litellm-tests (#42902) 2026-09-24 15:49:59 -07:00
_event_loop_reuse.py fix(caching): key cached async clients by a per-loop token instead of id(loop) (#48877) 2026-10-29 13:14:48 -07:00
redis_batch_double.py refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_azure_blob_cache.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_cache_preset_key.py ci: move caching, proxy-extras, gateway and enterprise tests into tests/unit and run them from litellm-tests (#42902) 2026-09-24 15:49:59 -07:00
test_caching.py fix(gemini): support explicit text in embedding inputs (#53135) 2026-11-20 11:05:11 -08:00
test_caching_handler.py perf(caching): hash response cache keys piece by piece and store under the looked-up key (#52267) 2026-11-17 15:58:07 -08:00
test_check_and_fix_namespace_none_guard.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_dual_cache.py perf(caching): format dual cache debug logs lazily (#51902) 2026-11-15 06:50:04 +00:00
test_embedding_router.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_evicted_client_closer.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_gcs_cache.py test: migrate legacy unit dirs and unrun folders into tests/unit, tests/integration and tests/e2e (#45940) 2026-10-11 06:24:57 -07:00
test_in_memory_cache.py feat(router): add deployment rpd and tpd daily limits to enforce_model_rate_limits (#48875) 2026-10-28 15:52:44 -07:00
test_llm_caching_handler.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_llm_client_cache_e2e.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_qdrant_semantic_cache.py perf(token_counter): memoize token counts of long texts per tokenizer (#51904) 2026-11-16 19:21:55 +00:00
test_redis_batch.py refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_redis_cache.py fix(responses): stop the background stream when a polling response is cancelled (#49384) 2026-11-18 14:33:39 +00:00
test_redis_cluster_cache.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_redis_cluster_node_isolation.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_redis_connection_pool.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_redis_semantic_cache.py perf(token_counter): memoize token counts of long texts per tokenizer (#51904) 2026-11-16 19:21:55 +00:00
test_request_redis_batch_post_call.py refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_request_redis_batch_pre_call.py refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_responses_stream_cache_keys.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00:00
test_s3_cache.py test: move routing, caching and callback tests out of local_testing (#45761) 2026-10-10 09:33:09 -07:00
test_unit_test_caching.py fix(caching): read the cache key's model group from the router's metadata for the call (#48917) 2026-10-29 05:35:23 -07:00
test_valkey_semantic_cache.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