n8n-io/n8n · error · Error

Guardrail "${this.name}" requires a type

Error message

Guardrail "${this.name}" requires a type

What it means

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.

Source

Thrown at packages/@n8n/agents/src/sdk/guardrail.ts:39

	}

	strategy(strategy: GuardrailStrategy): this {
		this.strategyType = strategy;
		return this;
	}

	detect(types: PiiDetectionType[]): this {
		this.detectionTypes = types;
		return this;
	}

	threshold(value: number): this {
		this.thresholdValue = value;
		return this;
	}

	build(): BuiltGuardrail {
		if (!this.guardType) throw new Error(`Guardrail "${this.name}" requires a type`);
		if (!this.strategyType) throw new Error(`Guardrail "${this.name}" requires a strategy`);

		return {
			name: this.name,
			guardType: this.guardType,
			strategy: this.strategyType,
			_config: {
				detectionTypes: this.detectionTypes,
				threshold: this.thresholdValue,
			},
		};
	}
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Call .type('pii' | other GuardrailType) before the guardrail is consumed.
  2. Keep builder chains linear and end with the consuming call to make missing steps obvious.
  3. Add a unit test that builds each guardrail to catch missing required setters at test time.

Example fix

// before
const g = new Guardrail('pii-out').strategy('block');
// after
const g = new Guardrail('pii-out').type('output').strategy('block');
Defensive patterns

Strategy: validation

Validate before calling

function assertGuardTypeSet(g: { guardType?: string }) {
  if (!g.guardType) throw new Error('Guardrail missing .type()');
}

Type guard

function guardHasType(g: { guardType?: string }): g is { guardType: string } {
  return typeof g.guardType === 'string' && g.guardType.length > 0;
}

Prevention

When it happens

Trigger: 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().

Common situations: 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().

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/68daf328cc69a830. Report an issue: GitHub.