API Reference: Security¶
The openjarvis.security package provides text scanning, content guardrails, file path filtering, and audit logging. All public components are documented below.
For usage examples and configuration, see the Security user guide. For the architectural design, see Security architecture.
Types¶
Core data types shared across the security subsystem.
ThreatLevel¶
Severity classification for individual scan findings. Ordered from least to most severe: LOW < MEDIUM < HIGH < CRITICAL.
ThreatLevel
¶
Bases: str, Enum
Severity classification for security findings.
RedactionMode¶
Controls the action taken by GuardrailsEngine when findings are detected.
RedactionMode
¶
Bases: str, Enum
Action mode when findings are detected.
SecurityEventType¶
Categories of security events recorded by AuditLogger.
SecurityEventType
¶
Bases: str, Enum
Categories of security events.
ScanFinding¶
A single match produced by a scanner. Includes the pattern name, matched text, position, threat level, and a human-readable description.
ScanFinding
dataclass
¶
ScanFinding(pattern_name: str, matched_text: str, threat_level: ThreatLevel, start: int, end: int, description: str = '')
A single finding from a security scanner.
ScanResult¶
Aggregated result from one or more scanner passes. The clean property returns True when no findings were detected; highest_threat returns the most severe ThreatLevel found.
ScanResult
dataclass
¶
ScanResult(findings: List[ScanFinding] = list())
Aggregated result from one or more scanners.
Attributes¶
highest_threat
property
¶
highest_threat: Optional[ThreatLevel]
Return the highest threat level among findings, or None.
SecurityEvent¶
A recorded security event, as persisted by AuditLogger.
SecurityEvent
dataclass
¶
SecurityEvent(event_type: SecurityEventType, timestamp: float, findings: List[ScanFinding] = list(), content_preview: str = '', action_taken: str = '')
A recorded security event for audit logging.
BaseScanner¶
BaseScanner is the abstract base class for all scanner implementations. Implement both scan() and redact() to create a custom scanner.
BaseScanner
¶
Bases: ABC
Base class for all security scanners.
Subclasses implement pattern-based scanning for secrets, PII, or other sensitive content.
Functions¶
scan
abstractmethod
¶
scan(text: str) -> ScanResult
SecretScanner¶
Detects API keys, tokens, passwords, and credentials in text using regex patterns. See the pattern reference table in the user guide for the full list of patterns and their threat levels.
SecretScanner
¶
Bases: BaseScanner
Detect API keys, tokens, passwords, and other secrets in text.
Functions¶
scan
¶
scan(text: str) -> ScanResult
Scan text for secret patterns.
Source code in src/openjarvis/security/scanner.py
redact
¶
Replace secret matches with [REDACTED:{pattern_name}].
Source code in src/openjarvis/security/scanner.py
PIIScanner¶
Detects personally identifiable information including email addresses, Social Security Numbers, credit card numbers, phone numbers, and public IP addresses.
PIIScanner
¶
Bases: BaseScanner
Detect personally identifiable information in text.
Functions¶
scan
¶
scan(text: str) -> ScanResult
Scan text for PII patterns.
Source code in src/openjarvis/security/scanner.py
redact
¶
Replace PII matches with [REDACTED:{pattern_name}].
Source code in src/openjarvis/security/scanner.py
GuardrailsEngine¶
GuardrailsEngine wraps any InferenceEngine with security scanning on both input and output. It implements the full InferenceEngine interface, so it can be used anywhere an engine is expected.
Registration
GuardrailsEngine is not registered in EngineRegistry. Instantiate it directly by wrapping an existing engine instance.
GuardrailsEngine
¶
GuardrailsEngine(engine: InferenceEngine, *, scanners: Optional[List[BaseScanner]] = None, mode: RedactionMode = WARN, scan_input: bool = True, scan_output: bool = True, bus: Optional[EventBus] = None)
Bases: InferenceEngine
Wraps an existing InferenceEngine with security scanning.
Not registered in EngineRegistry — instantiated dynamically to wrap
any engine at runtime.
| PARAMETER | DESCRIPTION |
|---|---|
engine
|
The wrapped inference engine.
TYPE:
|
scanners
|
List of scanners to run. Defaults to
TYPE:
|
mode
|
Action taken on findings: WARN, REDACT, or BLOCK.
TYPE:
|
scan_input
|
Whether to scan input messages.
TYPE:
|
scan_output
|
Whether to scan output content.
TYPE:
|
bus
|
Optional event bus for publishing security events.
TYPE:
|
Source code in src/openjarvis/security/guardrails.py
Attributes¶
Functions¶
generate
¶
generate(messages: Sequence[Message], *, model: str, temperature: float = 0.7, max_tokens: int = 1024, **kwargs: Any) -> Dict[str, Any]
Scan input, call wrapped engine, scan output.
Source code in src/openjarvis/security/guardrails.py
stream
async
¶
stream(messages: Sequence[Message], *, model: str, temperature: float = 0.7, max_tokens: int = 1024, **kwargs: Any) -> AsyncIterator[str]
Yield tokens in real-time, scan accumulated output post-hoc.
Source code in src/openjarvis/security/guardrails.py
list_models
¶
SecurityBlockError¶
Raised by GuardrailsEngine when mode=RedactionMode.BLOCK and findings are detected during a scan. Catch this exception to handle blocked requests gracefully.
from openjarvis.security.guardrails import GuardrailsEngine, SecurityBlockError
from openjarvis.security.types import RedactionMode
guarded = GuardrailsEngine(engine, mode=RedactionMode.BLOCK)
try:
response = guarded.generate(messages, model="qwen3:8b")
except SecurityBlockError as exc:
# exc.args[0] describes the direction and finding count
print(f"Request blocked: {exc}")
SecurityBlockError
¶
Bases: Exception
Raised when mode is BLOCK and security findings are detected.
File Policy¶
Functions and constants for filtering sensitive file paths. Used internally by FileReadTool and the memory ingest path.
DEFAULT_SENSITIVE_PATTERNS¶
The default set of glob patterns used to identify sensitive files. This is a frozenset[str] exported from openjarvis.security.file_policy.
See the sensitive file patterns table in the user guide for the complete list.
DEFAULT_SENSITIVE_PATTERNS
module-attribute
¶
DEFAULT_SENSITIVE_PATTERNS: frozenset[str] = frozenset({'.env', '.env.*', '*.env', '.secret', '*.secrets', 'credentials.*', '*.pem', '*.key', '*.p12', '*.pfx', '*.jks', 'id_rsa', 'id_ed25519', '.htpasswd', '.pgpass', '.netrc'})
is_sensitive_file¶
is_sensitive_file
¶
Return True if path matches a sensitive file pattern.
Checks both the filename and the full name against
DEFAULT_SENSITIVE_PATTERNS using :func:fnmatch.fnmatch.
Source code in src/openjarvis/security/file_policy.py
filter_sensitive_paths¶
filter_sensitive_paths
¶
AuditLogger¶
Append-only SQLite-backed storage for security events. Subscribes to SECURITY_SCAN, SECURITY_ALERT, and SECURITY_BLOCK events on the EventBus when a bus is provided.
The default database path is ~/.openjarvis/audit.db, overridable via security.audit_log_path in config.toml.
from openjarvis.core.events import EventBus
from openjarvis.security.audit import AuditLogger
from openjarvis.security.guardrails import GuardrailsEngine
from openjarvis.security.types import RedactionMode
bus = EventBus()
audit = AuditLogger(bus=bus)
guarded = GuardrailsEngine(engine, mode=RedactionMode.WARN, bus=bus)
# Security events from guarded engine are now persisted automatically
events = audit.query(limit=10)
print(f"Logged {audit.count()} events")
audit.close()
AuditLogger
¶
AuditLogger(db_path: Union[str, Path] = DEFAULT_CONFIG_DIR / 'audit.db', bus: Optional[EventBus] = None)
Append-only SQLite audit log for security events.
| PARAMETER | DESCRIPTION |
|---|---|
db_path
|
Path to the SQLite database file.
TYPE:
|
bus
|
Optional event bus — if provided, subscribes to security events
(
TYPE:
|
Source code in src/openjarvis/security/audit.py
Functions¶
log
¶
log(event: SecurityEvent) -> None
Insert a security event into the audit log.
Source code in src/openjarvis/security/audit.py
query
¶
query(*, event_type: Optional[str] = None, since: Optional[float] = None, limit: int = 100) -> List[SecurityEvent]
Query logged security events with optional filters.
Source code in src/openjarvis/security/audit.py
count
¶
Return the total number of logged security events.