Skip to content

Conversation

Pouyanpi
Copy link
Collaborator

Extends the LLM caching system to support jailbreak detection. The jailbreak detection action now caches results with metadata, properly tracks call information for tracing, and includes a fix to skip unnecessary LLM initialization for jailbreak detection models in the Rails configuration.

Changes

  • Added caching support to jailbreak_detection_model() with cache hit/miss logic
  • Implemented LLM call info tracking for jailbreak detection (duration, timestamps, cache status)
  • Added processing log integration for tracing jailbreak detection calls
  • Modified LLMRails to skip LLM initialization for jailbreak_detection type models
  • Comprehensive test coverage including cache hits, misses, and model initialization behavior
  • Tests verify that jailbreak detection models with cache configs are registered correctly

Dependencies

Part of Stack

This is PR 4/5 in the NeMoGuards caching feature stack.

@Pouyanpi Pouyanpi changed the title Feat/cache jailbreak detection feat(cache): add caching support for jailbreak detection Oct 17, 2025
@Pouyanpi Pouyanpi changed the base branch from develop to feat/cache-safety-checks October 17, 2025 10:31
@Pouyanpi Pouyanpi force-pushed the feat/cache-jailbreak-detection branch from 6a7474e to 630eafa Compare October 17, 2025 10:35
@Pouyanpi Pouyanpi force-pushed the feat/cache-safety-checks branch from 5c3d2bb to fab35c0 Compare October 17, 2025 10:40
@Pouyanpi Pouyanpi force-pushed the feat/cache-jailbreak-detection branch from 630eafa to 9dbb323 Compare October 17, 2025 10:40
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@tgasser-nv tgasser-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of nits and replicating the tests to check caching when we use a local jailbreak model rather than client-server API interface

@Pouyanpi Pouyanpi force-pushed the feat/cache-safety-checks branch from fab35c0 to ef6444d Compare October 19, 2025 10:10
Base automatically changed from feat/cache-safety-checks to develop October 19, 2025 10:18
Extends the cache system to store and restore LLM metadata (model name
and provider name) alongside cache entries. This allows cached results
to maintain provenance information about which model and provider
generated the original response.

- Added LLMMetadataDict and LLMCacheData TypedDict definitions for type
safety
  - Extended CacheEntry to include optional llm_metadata field
  - Implemented extract_llm_metadata_for_cache() to capture model and
provider info from context
  - Implemented restore_llm_metadata_from_cache() to restore metadata
when retrieving cached results
  - Updated get_from_cache_and_restore_stats() to handle metadata
extraction and restoration
  - Added comprehensive test coverage for metadata caching functionalit
Extends the LLM caching system to support jailbreak detection. The
jailbreak detection action now caches results with metadata, properly
tracks call information for tracing, and includes a fix to skip
unnecessary LLM initialization for jailbreak detection models in the
Rails configuration.

  Changes

  - Added caching support to jailbreak_detection_model() with cache
hit/miss logic
  - Implemented LLM call info tracking for jailbreak detection
(duration, timestamps, cache status)
  - Added processing log integration for tracing jailbreak detection
calls
  - Modified LLMRails to skip LLM initialization for jailbreak_detection
type models
  - Comprehensive test coverage including cache hits, misses, and model
initialization behavior
  - Tests verify that jailbreak detection models with cache configs are
registered correctly

update license
@Pouyanpi Pouyanpi force-pushed the feat/cache-jailbreak-detection branch from 9dbb323 to d38eb0b Compare October 19, 2025 10:26
@Pouyanpi Pouyanpi merged commit ce7b866 into develop Oct 19, 2025
7 checks passed
@Pouyanpi Pouyanpi deleted the feat/cache-jailbreak-detection branch October 19, 2025 10:38
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