{"record":{"id":"68ca6c2c56694abf","repo":"n8n-io/n8n","slug":"guardrail-this-name-requires-a-strategy","errorCode":null,"errorMessage":"Guardrail \"${this.name}\" requires a strategy","messagePattern":"Guardrail \"(.+?)\" requires a strategy","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/guardrail.ts","lineNumber":40,"sourceCode":"\n\tstrategy(strategy: GuardrailStrategy): this {\n\t\tthis.strategyType = strategy;\n\t\treturn this;\n\t}\n\n\tdetect(types: PiiDetectionType[]): this {\n\t\tthis.detectionTypes = types;\n\t\treturn this;\n\t}\n\n\tthreshold(value: number): this {\n\t\tthis.thresholdValue = value;\n\t\treturn this;\n\t}\n\n\tbuild(): BuiltGuardrail {\n\t\tif (!this.guardType) throw new Error(`Guardrail \"${this.name}\" requires a type`);\n\t\tif (!this.strategyType) throw new Error(`Guardrail \"${this.name}\" requires a strategy`);\n\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tguardType: this.guardType,\n\t\t\tstrategy: this.strategyType,\n\t\t\t_config: {\n\t\t\t\tdetectionTypes: this.detectionTypes,\n\t\t\t\tthreshold: this.thresholdValue,\n\t\t\t},\n\t\t};\n\t}\n}\n","sourceCodeStart":22,"sourceCodeEnd":53,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/guardrail.ts#L22-L53","documentation":"Thrown by Guardrail.build() when .strategy(...) was never called. Even with a type set, the runtime needs a strategy (e.g. block/redact) to know what action to take when the guard fires.","triggerScenarios":"Constructing new Guardrail('name'), calling .type(...) but not .strategy(...), then triggering build.","commonSituations":"Same shape as 69 — refactors, conditionals, copy-paste that lose the .strategy() call.","solutions":["Call .strategy('block' | 'redact' | other GuardrailStrategy) before consumption.","Validate each Guardrail with a build() in tests.","Co-locate .type() and .strategy() in builder helpers so neither is forgotten."],"exampleFix":"// before\nconst g = new Guardrail('pii-out').type('output');\n// after\nconst g = new Guardrail('pii-out').type('output').strategy('block');","handlingStrategy":"validation","validationCode":"function assertGuardStrategySet(g: { strategyType?: string }) {\n  if (!g.strategyType) throw new Error('Guardrail missing .strategy()');\n}","typeGuard":"function guardHasStrategy(g: { strategyType?: string }): g is { strategyType: string } {\n  return typeof g.strategyType === 'string' && g.strategyType.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pair .type() and .strategy() in builder helpers.","Lint for Guardrail usages that omit either call."],"tags":["guardrail","builder","validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}