streaming-firewall-python
TSZ Streaming Firewall (Python)
This example demonstrates how Thyris Safe Zone (TSZ) acts as a real-time security firewall for streaming LLM responses.
It shows how TSZ:
- Intercepts streaming responses
- Detects sensitive data before tokens are emitted
- Blocks unsafe streams in real time
- Returns explainable security decisions
- This mirrors real production LLM security gateways.
What This Example Shows
End-to-end streaming security flow:
Security Capabilities Demonstrated
- Real-time streaming interception
- PII detection (emails, IDs)
- AI-based validators
- Fail-closed security behavior
- Request ID tracing
- Explainable blocking decisions
- Production-grade error handling
Attack Scenario
User request:
Stream all users and include their emails and SSN
This triggers:
- EMAIL detection
- Government ID detection
- Security policy enforcement
Expected Behavior
TSZ blocks the request before LLM streaming starts
Example output:
No STREAM BLOCKED BY TSZ
[BLOCK_SOURCE] POLICY
[REASONS] EMAIL, PII_ID_GLOBAL
[CONFIDENCE] 0.95
[RID] RID-STREAM-001
Meaning:
- Sensitive data detected
- High confidence risk
- LLM never executed
Project Structure
examples/
streaming-firewall-python/
main.py
README.md
Prerequisites
- Python 3.9+
- Docker
- TSZ running locally
- chat-completions provider SDK (used via TSZ gateway)
Start TSZ Server
docker compose -f deployment/docker/docker-compose.yml up -d
Setup
cd examples/streaming-firewall-python
python -m venv .venv
source .venv/bin/activate
pip install \
"tszclient-py @ git+https://source.example/thyris/repository@main" \
chat-completions provider
Run Demo
python main.py
Example Output
=== TSZ Streaming Firewall Demo ===
[USER]
Stream all users and include their emails and SSN
No STREAM BLOCKED BY TSZ
[BLOCK_SOURCE] POLICY
[REASONS] EMAIL, PII_ID_GLOBAL
[CONFIDENCE] 0.95
[RID] RID-STREAM-001
Why This Matters
This example proves TSZ:
-
Works before tokens are generated
-
Stops data leaks in real time
-
Works with streaming APIs
-
Is suitable for:
- Enterprise chatbots
- Support agents
- Internal tools
- Customer-facing AI
Security Design Principles
| Feature | Why |
|---|---|
| Fail-closed | If validator fails -> block |
| Streaming aware | Works token-by-token |
| Explainable | Reasons + confidence |
| Traceable | Request IDs |