Deterministic Safety Shields: Priority Tier Protection Mechanisms
Formal Syntactic Safeguards for Directives, Code Blocks, and Structured Data
Mathematical intuition
Overrides TF-IDF and centrality scores for sentences matching Tier 4 deterministic regex patterns and AST code fence boundaries.
- 01Pure statistical sentence scoring risks dropping low-frequency imperative directives.
- 02v0.3.1 applies protected priority according to caller-supplied provenance; untrusted RAG, tool, and assistant content cannot obtain Tier 4 from wording.
- 03Ensures AST syntactic integrity for Python, JavaScript, and JSON code snippets embedded in prompts.
1. Priority Tier Classification Specification
To ensure prompt compression never breaks application invariants, sentences are classified into four discrete priority tiers:
- **Tier 4 (trusted provenance)**: Protected priority is available to trusted system/developer context. In v0.3.1, untrusted RAG, tool, and assistant content is capped at Tier 2 regardless of imperative wording.
- **Tier 3 (Entity Protection - High Priority)**: Sentences containing proper nouns, numbers, currency symbols, and technical identifiers.
- **Tier 2 (Informative Content - Scored)**: Standard informative sentences evaluated by graph centrality.
- **Tier 1 (Structural Padding - Eligible for Pruning)**: Low-centrality conversational fluff.
llmslim/modes.py
import re
TIER_4_PATTERNS = [
re.compile(r"\b(must|never|always|required|strictly|do not|shall not)\b", re.IGNORECASE),
re.compile(r"^(system|developer|user|assistant):", re.IGNORECASE),
]
def evaluate_sentence_priority(sentence: str, is_inside_code_fence: bool) -> int:
"""Evaluates deterministic priority tier for a given sentence boundary."""
if is_inside_code_fence:
return 4
for pattern in TIER_4_PATTERNS:
if pattern.search(sentence):
return 4
return 2 # Default candidate for centrality scoring- [LLMSlim Core Docs]LLMSlim Core Engine Architecture & Priority Shield Implementation