n8n-io/n8n · error · NodeOperationError
Failed to sanitize text
Error message
Failed to sanitize text
What it means
Thrown by the Guardrails node's process handler when operation mode is 'sanitize' and at least one registered guardrail produced a failed result. In sanitize mode any failure is fatal because the operation's contract is to return only fully-clean text; the error message is fixed and the failing guardrails are summarized in the description via mapGuardrailErrorsToMessage.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/Guardrails/actions/process.ts:60
const guardrails = this.getNodeParameter('guardrails', itemIndex) as GuardrailsOptions;
const customizeSystemMessage =
operation === 'classify' &&
(this.getNodeParameter('customizeSystemMessage', itemIndex, false) as boolean);
const systemMessage = customizeSystemMessage
? (this.getNodeParameter('systemMessage', itemIndex) as string)
: undefined;
const failedChecks: GuardrailUserResult[] = [];
const passedChecks: GuardrailUserResult[] = [];
const handleFailedResults = (results: GroupedGuardrailResults): GuardrailUserResult[] => {
const unexpectedError = results.failed.find(
(result) =>
result.status === 'rejected' ||
(result.status === 'fulfilled' && result.value.executionFailed),
);
if (results.failed.length && operation === 'sanitize') {
throw new NodeOperationError(this.getNode(), 'Failed to sanitize text', {
description: mapGuardrailErrorsToMessage(results.failed),
itemIndex,
});
}
if (unexpectedError && !this.continueOnFail()) {
const error =
unexpectedError.status === 'rejected'
? unexpectedError.reason
: unexpectedError.value.originalException;
throw new NodeOperationError(this.getNode(), error, {
description: error?.description || error?.message,
itemIndex,
});
}
return results.failed.map(mapGuardrailResultToUserResult);
};
const stageGuardrails: StageGuardRails = {View on GitHub (pinned to 5ac6606e81)
Solutions
- Switch the node operation from 'sanitize' to 'validate' or 'filter' if you want failing items retained rather than aborting the run.
- Inspect the error description to see which guardrail(s) failed and tighten or relax that guardrail's configuration.
- Sanitize the upstream input (remove the offending content) before it reaches the node.
- Enable 'Continue On Fail' on the node if you want partial results despite a guardrail trip.
Example fix
// before: node operation = 'sanitize', input contains flagged PII // after: change node parameter operation to 'validate' to keep items and report status, // or narrow the PII guardrail entities list to the ones you actually want to block
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-screen input against the same guardrails in 'validate' mode before running 'sanitize'.
Try / catch
try {
await guardrailsNode.run({ operation: 'sanitize', ... });
} catch (e) {
if (e.message === 'Failed to sanitize text') {
// route to a remediation branch instead of failing the workflow
} else throw e;
} Prevention
- Use 'validate' or 'filter' when you must retain items despite guardrail trips.
- Enable Continue On Fail when sanitize aborts the run too aggressively.
- Tighten guardrail rules so expected content is not flagged.
When it happens
Trigger: handleFailedResults() is called with the grouped results; when results.failed.length > 0 AND operation === 'sanitize', it throws a NodeOperationError carrying itemIndex and a description listing which guardrails failed. Triggers: a banned-content/PII/moderation guardrail tripping while the node is set to sanitize; an LLM guardrail returning flagged=true; a rejected guardrail promise in sanitize mode.
Common situations: Running the Guardrails node in 'sanitize' mode against input that contains PII or disallowed content; a guardrail misconfigured with an overly broad rule; an LLM-backed guardrail whose model returns a parseable but 'flagged' verdict; combining multiple guardrails where one is strict.
Related errors
- error?.description || error?.message
- Invalid URL in allow list: "${entry}" - ${error instanceof E
- Chat Model is required
- error?.description || error?.message || 'Unknown error'
- Invalid output format
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/808a58e7d1ca873a.
Report an issue: GitHub.