SystemPromptScrubber
SystemPromptScrubber 是一个 输出处理器,它能够检测和处理系统提示、指令以及其他可能引入安全漏洞的敏感信息。该处理器通过识别各种类型的系统提示并提供灵活的处理策略来帮助维护安全,包括多种信息删除方法,以确保敏感信息得到妥善清理。
🌐 The SystemPromptScrubber is an output processor that detects and handles system prompts, instructions, and other revealing information that could introduce security vulnerabilities. This processor helps maintain security by identifying various types of system prompts and providing flexible strategies for handling them, including multiple redaction methods to ensure sensitive information is properly sanitized.
使用示例Direct link to 使用示例
🌐 Usage example
import { SystemPromptScrubber } from "@mastra/core/processors";
const processor = new SystemPromptScrubber({
model: "openrouter/openai/gpt-oss-safeguard-20b",
strategy: "redact",
redactionMethod: "mask",
includeDetections: true
});
构造函数参数Direct link to 构造函数参数
🌐 Constructor parameters
options:
选项Direct link to 选项
🌐 Options
model:
strategy?:
customPatterns?:
includeDetections?:
instructions?:
redactionMethod?:
placeholderText?:
返回Direct link to 返回
🌐 Returns
id:
name?:
processOutputStream:
processOutputResult:
扩展使用示例Direct link to 扩展使用示例
🌐 Extended usage example
在使用 SystemPromptScrubber 作为输出处理器时,建议将其与 BatchPartsProcessor 结合使用以优化性能。BatchPartsProcessor 会将流块批量组合在一起,然后再传递给清理器,从而减少检测所需的 LLM 调用次数。
🌐 When using SystemPromptScrubber 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 scrubber, reducing the number of LLM calls required for detection.
import { Agent } from "@mastra/core/agent";
import { BatchPartsProcessor, SystemPromptScrubber } from "@mastra/core/processors";
export const agent = new Agent({
name: "scrubbed-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 system prompt detection on batched content
new SystemPromptScrubber({
model: "openrouter/openai/gpt-oss-safeguard-20b",
strategy: "redact",
customPatterns: ["system prompt", "internal instructions"],
includeDetections: true,
redactionMethod: "placeholder",
placeholderText: "[REDACTED]"
}),
]
});
相关Direct link to 相关
🌐 Related