Pystreams (Risk & PII Scanning)
Relevant source files
The following files were used as context for generating this wiki page:
Pystreams is the scanning and enforcement engine within Speakeasy that inspects chat messages and tool calls for security risks. It identifies sensitive data exposure, such as Personally Identifiable Information (PII) and secrets, while enforcing organizational risk policies in real-time.
The system operates as an observability and security layer that intercepts data before it leaves the environment. It uses various detector families to categorize findings and can be configured to flag, warn, or block activity based on the detected risk level.
Sources: README.md, server/internal/assistants/managed_assistant_instructions.txt:44-50
Risk Detection Framework
The risk detection framework utilizes several specialized "source" families to identify different types of threats within agent conversations and tool executions.
Detector Families
| Source | Description | Details |
|---|---|---|
gitleaks | Secret Scanner | Detects API keys, tokens, and credentials using regex-based scanning. |
presidio | PII Scanner | Identifies PII entities such as emails, SSNs, and credit card numbers. |
prompt_injection | LLM Judge | Analyzes messages for attempts to bypass model constraints or inject malicious prompts. |
shadow_mcp | MCP Validator | Flags calls to MCP servers that are not on the organization's approved list. |
destructive_tool | Intent Analysis | Matches tool calls against patterns indicating destructive actions. |
Sources: server/internal/assistants/managed_assistant_instructions.txt:46-50, client/dashboard/src/pages/security/PolicyStart.tsx:32-40
Scanning Logic Flow
The following diagram illustrates how Pystreams processes messages and tool calls through the risk policies.
The system evaluates input against active policies and executes the configured remediation action (Flag, Warn, or Block).
Sources: client/dashboard/src/pages/security/PolicyStart.tsx:42-47, server/internal/assistants/managed_assistant_instructions.txt:44-46
Sensitive Data Handling (PII & Secrets)
Pystreams implements a "Hard Rule" for data privacy to ensure that sensitive matched content is never exposed in raw form within the platform's analysis tools.
Redaction and Fingerprinting
Instead of storing the literal matched secret or PII, the system uses deterministic fingerprints.
- Match Redacted: Replaces raw matches with an opaque token containing the length and a SHA256-prefix fingerprint.
- Deduplication: Because fingerprints are deterministic, the system can count unique leaks across different chats without revealing the actual secret.
- Privacy Enforcement: Assistants and developers are strictly prohibited from attempting to reconstruct redacted secrets or quoting
match_redactedvalues.
Sources: server/internal/assistants/managed_assistant_instructions.txt:51-64, server/internal/assistants/testdata/managed_assistant_instructions_05c5372.txt:53-66
Risk Policies and Enforcement
Risk policies define the criteria for what constitutes a threat and the required response. Administrators can create policies from presets or bespoke prompt-based instructions.
Policy Actions
| Action | Behavior |
|---|---|
flag | Logs the finding for review in the Watchdog dashboard; does not interrupt the user. |
warn | Warns the end-user and requires them to confirm before proceeding. |
block | Immediately stops the prompt or tool call from being sent. |
quarantine | Blocks the action and freezes the session for administrator investigation. |
Sources: client/dashboard/src/pages/security/PolicyStart.tsx:42-47, client/dashboard/src/pages/security/PolicyStart.tsx:556-559
MCP Tool Approval Flow
For highly sensitive tools, Pystreams supports an explicit approval workflow that intercepts calls until an administrator provides authorization.
The sequence demonstrates the interception of protected tools where the agent must first obtain a "granted" status from the proxy.
Sources: examples/functions-approve/src/functions.ts:168-245, examples/functions-approve/readme.md:120-145
Monitoring and Auditing
Risk findings are aggregated into the Watchdog system for triage and reporting.
- Risk Results by Agent: Provides finding-level data for specific agents.
- Risk Results by Chat: Provides rollups of finding counts and latest detections per conversation.
- Policy Status: Monitors analysis progress, including pending versus analyzed message counts.
- Exclusions: Administrators can define exclusions to ignore specific matches or rules, identified by
rule_idand match type rather than raw values.
Sources: server/internal/assistants/managed_assistant_instructions.txt:51-60, client/dashboard/src/lib/insights-suggestions.ts:470-495
Summary
Pystreams serves as the critical security layer for the Speakeasy AI Control Plane. By combining automated detectors for PII and secrets with flexible enforcement policies and an air-gapped fingerprinting system, it enables organizations to observe and secure AI usage without exposing sensitive data to the observability platform itself.
Sources: README.md, REVIEW.md:105-115