{"record":{"id":"633b58a4acb9604d","repo":"mastra-ai/mastra","slug":"prompt-injection-detection-failed-error-instanc","errorCode":null,"errorMessage":"Prompt injection detection failed: ${error instanceof Error ? error.stack : 'Unknown error'}","messagePattern":"Prompt injection detection failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/processors/prompt-injection-detector.ts","lineNumber":234,"sourceCode":"            continue;\n          } else if (this.strategy === 'rewrite') {\n            if (processedMessage) {\n              processedMessages.push(processedMessage);\n            }\n            // If processedMessage is null (no rewrite available), skip the message\n            continue;\n          }\n        }\n\n        processedMessages.push(message);\n      }\n\n      return processedMessages;\n    } catch (error) {\n      if (error instanceof TripWire) {\n        throw error; // Re-throw tripwire errors\n      }\n      throw new Error(`Prompt injection detection failed: ${error instanceof Error ? error.stack : 'Unknown error'}`);\n    }\n  }\n\n  /**\n   * Notify the consumer-supplied `onDetection` callback. Never throws.\n   */\n  private async emitDetection(input: string, detectionResult: PromptInjectionResult, flagged: boolean): Promise<void> {\n    if (!this.onDetection) return;\n    try {\n      await this.onDetection({\n        detectionResult,\n        input,\n        flagged,\n        strategyApplied: flagged ? this.strategy : 'none',\n      });\n    } catch (error) {\n      console.warn('[PromptInjectionDetector] onDetection callback failed:', error);\n    }","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/processors/prompt-injection-detector.ts#L216-L252","documentation":"PromptInjectionDetectorProcessor.processInput wraps its detection pass: TripWire throws (an injection was intentionally flagged) are re-thrown unchanged, but any other exception during injection detection is re-thrown as this generic Error including the original stack. It means the detector itself malfunctioned, not that injection was detected.","triggerScenarios":"Detector internals throw due to invalid options (bad patterns/thresholds), model/API errors in model-based detection, unexpected message shapes, or bugs in consumer-supplied detection configuration.","commonSituations":"Misconfigured detection threshold or pattern options; detection model auth/network failures; message content that is not plain text (images/attachments) hitting string-only code paths; version drift in message internals after upgrades.","solutions":["Read the embedded original stack from the message for the root cause","Validate detector options (thresholds, patterns) at construction","Verify detection model credentials/connectivity if applicable","Catch TripWire separately in callers to distinguish intentional trips from processor failures"],"exampleFix":"// before\ntry { await processor.processInput(messages); } catch (e) { /* indistinguishable */ }\n// after\ntry {\n  await processor.processInput(messages);\n} catch (e) {\n  if (e instanceof TripWire) throw e; // intentional detection\n  throw e; // processor failure — inspect stack\n}","handlingStrategy":"try-catch","validationCode":"if (typeof options.threshold !== 'number' || options.threshold < 0 || options.threshold > 1) {\n  throw new TypeError('prompt-injection threshold must be a number between 0 and 1');\n}","typeGuard":"function isTripWire(e: unknown): e is TripWire {\n  return e instanceof TripWire;\n}\nfunction isInjectionProcessorFailure(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('Prompt injection detection failed');\n}","tryCatchPattern":"try {\n  processed = await processor.processInput(messages);\n} catch (e) {\n  if (isTripWire(e)) throw e; // intentional injection trip\n  if (isInjectionProcessorFailure(e)) {\n    logger.error('Injection detector crashed', { stack: e.message });\n    return messages; // or rethrow for fail-closed\n  }\n  throw e;\n}","preventionTips":["Validate detector thresholds/patterns in configuration","Handle TripWire separately from processor crashes in all callers","Ensure message content matches expected string shapes before processing","Monitor detection model availability if using AI-based detection"],"tags":["processors","prompt-injection","error-wrapping"],"backgroundTag":"processor-detection-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}