Skip to content
Cisco AI Defense logo
CiscoAI Security

Verdict cache — DefenseClaw

Overview

internal/guardrail/verdict_cache.go::VerdictCache is a correctness-neutral cache for LLM judge outcomes. It is wired from internal/gateway/llm_judge.go through SetJudgeVerdictCache, NewJudgeVerdictCache, and InvalidateJudgeVerdictCache.

It does not skip the whole guardrail scanner pipeline. It short-circuits repeated judge calls for the same judge kind, model, direction, and content.

Key shape

The key is built by cacheKey(kind, model, direction, content):

ComponentMeaning
kindJudge category such as injection, pii, or tool_injection.
modelJudge model string.
directionprompt, completion, or tool_call.
contentFull judge input content, or tool name plus arguments for tool-injection checks.

The stored entry also carries the current cache generation. Invalidate increments that generation; older entries remain in the map until eviction but are treated as misses.

Defaults and eviction

SettingSource-backed value
TTLConstructor argument, defaulting to 30s when non-positive.
Entry cap4096 entries by default.
EvictionOn Put, expired or generation-mismatched entries are swept first; if still full, one arbitrary map entry is removed.
MetricsOptional hit/miss callbacks record scanner, verdict, and TTL bucket labels.

Correctness properties

PropertyWhy it matters
Misses are safeA miss re-runs the judge.
Expired entries are removed on accessStale TTL entries do not return verdicts.
Generation mismatch is a missReloads can invalidate old decisions without clearing the map synchronously.
Not LRUThe cache uses a bounded map and arbitrary drop after stale sweep, not an LRU queue.

Related