{"record":{"id":"7f27fe5993db12d2","repo":"mastra-ai/mastra","slug":"systempromptscrubber-requires-a-model-for-detectio","errorCode":null,"errorMessage":"SystemPromptScrubber requires a model for detection","messagePattern":"SystemPromptScrubber requires a model for detection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/processors/system-prompt-scrubber.ts","lineNumber":83,"sourceCode":"\nexport class SystemPromptScrubber implements Processor<'system-prompt-scrubber'> {\n  public readonly id = 'system-prompt-scrubber';\n  public readonly name = 'System Prompt Scrubber';\n\n  private strategy: 'block' | 'warn' | 'filter' | 'redact';\n  private customPatterns: string[];\n  private includeDetections: boolean;\n  private instructions: string;\n  private redactionMethod: 'mask' | 'placeholder' | 'remove';\n  private placeholderText: string;\n  private model: MastraModelConfig;\n  private detectionAgent: Agent;\n  private lastMessageOnly: boolean;\n  private structuredOutputOptions?: SystemPromptScrubberOptions['structuredOutputOptions'];\n\n  constructor(options: SystemPromptScrubberOptions) {\n    if (!options.model) {\n      throw new Error('SystemPromptScrubber requires a model for detection');\n    }\n\n    this.strategy = options.strategy || 'redact';\n    this.customPatterns = options.customPatterns || [];\n    this.includeDetections = options.includeDetections || false;\n    this.redactionMethod = options.redactionMethod || 'mask';\n    this.placeholderText = options.placeholderText || '[SYSTEM_PROMPT]';\n    this.lastMessageOnly = options.lastMessageOnly ?? false;\n    this.structuredOutputOptions = options.structuredOutputOptions;\n\n    // Initialize instructions after customPatterns is set\n    this.instructions = options.instructions || this.getDefaultInstructions();\n\n    // Store the model for lazy initialization\n    this.model = options.model;\n\n    this.detectionAgent = new Agent({\n      id: 'system-prompt-detector',","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/processors/system-prompt-scrubber.ts#L65-L101","documentation":"SystemPromptScrubber detects (and redacts) embedded system-prompt text using an LLM-based detection agent, which itself needs a model. If `options.model` is missing, the constructor throws a plain Error because detection cannot run at all. All other options (strategy, patterns, redaction method) have defaults; the model does not.","triggerScenarios":"`new SystemPromptScrubber({})` or `new SystemPromptScrubber({ customPatterns: [...] })` without `model`, or `model: undefined` from an uninitialized/failed model factory.","commonSituations":"Assuming custom regex patterns alone are enough (detection still uses the agent), model constructed behind a feature flag that was off, forgetting to pass the model after upgrading to a constructor signature that requires it.","solutions":["Pass a model: `new SystemPromptScrubber({ model: 'openai/gpt-4o' })`.","Confirm the variable holding your model is defined at construction time.","If you only want pattern-based behavior, verify whether a non-LLM variant/config fits your use case before omitting the model.","Wrap processor construction in config validation that asserts required options exist."],"exampleFix":"// before\nnew SystemPromptScrubber({ strategy: 'redact' });\n// after\nnew SystemPromptScrubber({ strategy: 'redact', model: 'openai/gpt-4o' });","handlingStrategy":"validation","validationCode":"if (!options.model) throw new TypeError('SystemPromptScrubber: model is required');\nconst scrubber = new SystemPromptScrubber(options);","typeGuard":"function hasModel(o: SystemPromptScrubberOptions): o is SystemPromptScrubberOptions & { model: NonNullable<SystemPromptScrubberOptions['model']> } {\n  return Boolean(o.model);\n}","tryCatchPattern":"try {\n  scrubber = new SystemPromptScrubber(opts);\n} catch (e) {\n  if (e.message.includes('requires a model')) {\n    scrubber = new SystemPromptScrubber({ ...opts, model: DEFAULT_MODEL });\n  } else throw e;\n}","preventionTips":["Define a single model factory and assert it returns a model before building processors.","Wrap processor construction in a helper that injects default model config.","Add a startup smoke test that constructs all processors to surface missing options early."],"tags":["configuration","model","constructor","detection"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}