PII检测器
🌐 PIIDetector
PIIDetector 是一款 混合处理器,可用于输入和输出处理,以检测和编辑个人可识别信息(PII),以确保隐私合规。该处理器通过识别各种类型的 PII 并提供灵活的处理策略来帮助维护隐私,包括多种编辑方法,以确保符合 GDPR、CCPA、HIPAA 及其他隐私法规的要求。
🌐 The PIIDetector is a hybrid processor that can be used for both input and output processing to detect and redact personally identifiable information (PII) for privacy compliance. This processor helps maintain privacy by identifying various types of PII and providing flexible strategies for handling them, including multiple redaction methods to ensure compliance with GDPR, CCPA, HIPAA, and other privacy regulations.
使用示例Direct link to 使用示例
🌐 Usage example
import { PIIDetector } from "@mastra/core/processors";
const processor = new PIIDetector({
model: "openrouter/openai/gpt-oss-safeguard-20b",
threshold: 0.6,
strategy: "redact",
detectionTypes: ["email", "phone", "credit-card", "ssn"]
});
构造函数参数Direct link to 构造函数参数
🌐 Constructor parameters
options:
选项Direct link to 选项
🌐 Options
model:
detectionTypes?:
threshold?:
strategy?:
redactionMethod?:
instructions?:
includeDetections?:
preserveFormat?:
providerOptions?:
返回Direct link to 返回
🌐 Returns
id:
name?:
processInput:
processOutputStream:
扩展使用示例Direct link to 扩展使用示例
🌐 Extended usage example
输入处理Direct link to 输入处理
🌐 Input processing
import { Agent } from "@mastra/core/agent";
import { PIIDetector } from "@mastra/core/processors";
export const agent = new Agent({
name: "private-agent",
instructions: "You are a helpful assistant",
model: "openai/gpt-5.1",
inputProcessors: [
new PIIDetector({
model: "openrouter/openai/gpt-oss-safeguard-20b",
detectionTypes: ["email", "phone", "credit-card", "ssn"],
threshold: 0.6,
strategy: "redact",
redactionMethod: "mask",
instructions: "Detect and redact personally identifiable information while preserving message intent",
includeDetections: true,
preserveFormat: true
})
]
});
批处理输出处理Direct link to 批处理输出处理
🌐 Output processing with batching
在将 PIIDetector 用作输出处理器时,建议将其与 BatchPartsProcessor 结合使用以优化性能。BatchPartsProcessor 会在将数据块传递给 PII 检测器之前将流数据批量处理,从而减少检测所需的 LLM 调用次数。
🌐 When using PIIDetector as an output processor, it's recommended to combine it with BatchPartsProcessor to optimize performance. The BatchPartsProcessor batches stream chunks together before passing them to the PII detector, reducing the number of LLM calls required for detection.
import { Agent } from "@mastra/core/agent";
import { BatchPartsProcessor, PIIDetector } from "@mastra/core/processors";
export const agent = new Agent({
name: "output-pii-agent",
instructions: "You are a helpful assistant",
model: "openai/gpt-5.1",
outputProcessors: [
// Batch stream parts first to reduce LLM calls
new BatchPartsProcessor({
batchSize: 10,
}),
// Then apply PII detection on batched content
new PIIDetector({
model: "openrouter/openai/gpt-oss-safeguard-20b",
strategy: "redact",
})
]
});
相关Direct link to 相关
🌐 Related