Skip to content

fix: support Responses input in Redis semantic cache - #28612

Closed
balcsida wants to merge 8 commits into
BerriAI:litellm_oss_stagingfrom
balcsida:fix/redis-semantic-responses-input-shin-staging
Closed

balcsida wants to merge 8 commits into
BerriAI:litellm_oss_stagingfrom
balcsida:fix/redis-semantic-responses-input-shin-staging

Conversation

@balcsida

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #28272

Replaces #28274, which was closed after its previous staging base branch was deleted. This PR recreates the same Redis semantic cache fix on the current shin_agent_oss_staging_05_22_2026 base.

Linear ticket

N/A

Pre-Submission checklist

  • I have added testing in the tests/test_litellm directory
  • My PR passes all unit tests on make test-unit
  • My PR scope is isolated and solves one specific problem
  • I have requested a Greptile review

Screenshots / Proof of Fix

Before this change, RedisSemanticCache only extracted prompts from messages. Responses API calls pass input instead, so RedisVL store/check were skipped and the RediSearch index stayed empty.

Validation run locally:

uv run pytest tests/test_litellm/caching/test_redis_semantic_cache.py -q
........................                                                 [100%]
24 passed in 0.22s

uv run ruff check litellm/caching/caching.py litellm/caching/redis_semantic_cache.py tests/test_litellm/caching/test_redis_semantic_cache.py
All checks passed!

uv run black --check litellm/caching/caching.py litellm/caching/redis_semantic_cache.py tests/test_litellm/caching/test_redis_semantic_cache.py
All done!
3 files would be left unchanged.

I did not run the full make test-unit suite locally.

Type

Bug Fix
Test

Changes

  • Added RedisSemanticCache prompt extraction for Responses API input, while preserving existing chat messages extraction.
  • Supported string input and structured Responses input content lists.
  • Updated sync cache lookup to pass original kwargs through to backend caches so input and metadata are available to semantic caches.
  • Added regression tests for sync set/get, async set/get, structured Responses input extraction, wrapper passthrough, and blank text-key fallback handling.

@greptile-apps

greptile-apps Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes RedisSemanticCache skipping store/check operations for Responses API calls by extending prompt extraction to handle the input kwarg in addition to messages. The sync Cache.get_cache path is also updated to forward a filtered copy of kwargs (only input/messages and an isolated metadata dict) to backend caches so that semantic-similarity is available without leaking sensitive fields.

  • redis_semantic_cache.py: New _get_prompt_from_kwargs / _collect_responses_input_text / _coerce_response_input_value class-methods handle string, list, dict, and Pydantic-model input shapes; all four cache paths (sync/async set/get) now use them.
  • caching.py: Sync get_cache replaces the hard-coded messages=messages argument with _get_safe_cache_lookup_kwargs, which copies only the relevant fields and an empty metadata dict, then propagates semantic-similarity back to the original caller's metadata via _update_metadata_from_cache_lookup_kwargs.

Confidence Score: 5/5

Safe to merge — the change is additive and backward-compatible, existing messages-based cache lookups are unaffected.

The fix is isolated to prompt extraction and kwargs filtering, no existing code paths are altered in a breaking way, and 14 new mock-only tests cover the key branches.

No files require special attention.

Important Files Changed

Filename Overview
litellm/caching/redis_semantic_cache.py Adds _get_prompt_from_kwargs, _collect_responses_input_text, and _coerce_response_input_value helpers so that all four cache paths (sync/async set/get) can extract prompts from Responses API input in addition to chat messages. Logic is well-structured with correct early-exit and fallback handling.
litellm/caching/caching.py Sync get_cache now passes a filtered copy of kwargs (only messages, input, and a fresh empty metadata) to backend caches, then copies semantic-similarity back to the original metadata via _update_metadata_from_cache_lookup_kwargs. Also removes the long-standing dead kwargs.get("messages", []) no-op statement from the async path.
tests/test_litellm/caching/test_redis_semantic_cache.py Adds 14 new unit tests covering sync/async set+get with string input, structured Responses input flattening, model object coercion, blank-text fallback, missing-input no-op, dynamic cache wrapper passthrough, and sensitive-kwarg filtering. All tests use mocks and make no real network calls.
docker/Dockerfile.non_root Adds libatomic to both build stages; unrelated to the caching fix.
tests/test_litellm/interactions/test_openapi_compliance.py Adds budget_exceeded to the expected status enum and updates the date comment; unrelated to the caching fix.

Reviews (2): Last reviewed commit: "fix: filter sensitive cache lookup kwarg..." | Re-trigger Greptile

@ghost

ghost commented May 22, 2026

Copy link
Copy Markdown

🤖 litellm-agent: This PR is currently BLOCKED from merge.

Score: 4/5 ❌

Why blocked:

  • 1 unresolved reviewer concern (greptile) (unresolved_concern, -1 pts)

Details: Score docked for: 1 unresolved reviewer concern (greptile).

Fix the issues above and push an update — the bot will re-review automatically.

Note: This bot is still in beta and might not always work as expected. Please share any feedback via Slack.

@shivamrawat1
shivamrawat1 changed the base branch from shin_agent_oss_staging_05_22_2026 to litellm_oss_staging May 22, 2026 16:58
@balcsida
balcsida force-pushed the fix/redis-semantic-responses-input-shin-staging branch from 916a81f to 1f290e5 Compare May 23, 2026 11:13
@codecov

codecov Bot commented May 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@balcsida

balcsida commented May 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @shivamrawat1 for switching the base branch 🙇

@balcsida
balcsida force-pushed the fix/redis-semantic-responses-input-shin-staging branch from 732fe96 to 61abfa8 Compare May 23, 2026 19:50
@veria-ai

veria-ai Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

Medium: Async semantic cache logs request credentials

This PR filters the synchronous Redis semantic cache lookup kwargs, but the async lookup path still forwards the full request dictionary into the Redis semantic cache. That leaves async callers able to get request credentials written to semantic-cache verbose logs.

Security review

  • No new security issues were flagged in the latest review.
  • 1 previously flagged issue(s) appear fixed in the latest changes.
  • No review issues remain open on this pull request.

Risk: 5/10

Comment thread litellm/caching/caching.py Resolved
@balcsida

Copy link
Copy Markdown
Contributor Author

@greptileai

@krrish-berri-2

Copy link
Copy Markdown
Contributor

@balcsida could you add a screenshot or short video showing that this change works as expected? It really helps reviewers verify the fix quickly. Thanks!

@balcsida

Copy link
Copy Markdown
Contributor Author

I'm not sure what would be the best was to demonstrate this, but here you go: https://asciinema.org/a/KEiuqzzoUE7NlUkK

@mateo-berri
mateo-berri deleted the branch BerriAI:litellm_oss_staging June 2, 2026 15:48
@mateo-berri mateo-berri closed this Jun 2, 2026
@balcsida

balcsida commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@mateo-berri why? :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants