{"record":{"id":"68daf328cc69a830","repo":"n8n-io/n8n","slug":"guardrail-this-name-requires-a-type","errorCode":null,"errorMessage":"Guardrail \"${this.name}\" requires a type","messagePattern":"Guardrail \"(.+?)\" requires a type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/sdk/guardrail.ts","lineNumber":39,"sourceCode":"\t}\n\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":21,"sourceCodeEnd":53,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/sdk/guardrail.ts#L21-L53","documentation":"Thrown by Guardrail.build() when .type(...) was never called. A guardrail needs both a guardType (e.g. input/output classification) and a strategy before it can be applied; without a type the runtime cannot decide where or how to invoke the guard.","triggerScenarios":"Constructing new Guardrail('name'), optionally calling .strategy/.detect/.threshold, then passing the builder to a consumer that triggers build (e.g. agent.inputGuardrail/guardrails) without calling .type().","commonSituations":"Copy-paste of a guardrail chain that drops the .type() line; conditional configuration behind a flag that resolved false; refactoring from a typed enum to another without re-adding .type().","solutions":["Call .type('pii' | other GuardrailType) before the guardrail is consumed.","Keep builder chains linear and end with the consuming call to make missing steps obvious.","Add a unit test that builds each guardrail to catch missing required setters at test time."],"exampleFix":"// before\nconst g = new Guardrail('pii-out').strategy('block');\n// after\nconst g = new Guardrail('pii-out').type('output').strategy('block');","handlingStrategy":"validation","validationCode":"function assertGuardTypeSet(g: { guardType?: string }) {\n  if (!g.guardType) throw new Error('Guardrail missing .type()');\n}","typeGuard":"function guardHasType(g: { guardType?: string }): g is { guardType: string } {\n  return typeof g.guardType === 'string' && g.guardType.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Build a makeGuardrail(name, type, strategy) helper so type/strategy are constructor params.","Unit-test each Guardrail.build() to catch missing required setters."],"tags":["guardrail","builder","validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}