guardrails
guardrails
¶
GuardrailsEngine — security-aware inference engine wrapper.
Classes¶
SecurityBlockError
¶
Bases: Exception
Raised when mode is BLOCK and security findings are detected.
GuardrailsEngine
¶
GuardrailsEngine(
engine: InferenceEngine,
*,
scanners: Optional[List[BaseScanner]] = None,
mode: RedactionMode = REDACT,
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/diapason/security/guardrails.py
Attributes¶
Methods:¶
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/diapason/security/guardrails.py
stream
async
¶
stream(
messages: Sequence[Message],
*,
model: str,
temperature: float = 0.7,
max_tokens: int = 1024,
**kwargs: Any,
) -> AsyncIterator[str]
Use the same safe boundaries as rich output, including long secrets.
Source code in src/diapason/security/guardrails.py
stream_full
async
¶
stream_full(
messages: Sequence[Message],
*,
model: str,
temperature: float = 0.7,
max_tokens: int = 1024,
**kwargs: Any,
) -> AsyncIterator[StreamChunk]
Stream verified text without releasing tools or terminal data early.