{"record":{"id":"808a58e7d1ca873a","repo":"n8n-io/n8n","slug":"failed-to-sanitize-text","errorCode":null,"errorMessage":"Failed to sanitize text","messagePattern":"Failed to sanitize text","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/Guardrails/actions/process.ts","lineNumber":60,"sourceCode":"\tconst guardrails = this.getNodeParameter('guardrails', itemIndex) as GuardrailsOptions;\n\tconst customizeSystemMessage =\n\t\toperation === 'classify' &&\n\t\t(this.getNodeParameter('customizeSystemMessage', itemIndex, false) as boolean);\n\tconst systemMessage = customizeSystemMessage\n\t\t? (this.getNodeParameter('systemMessage', itemIndex) as string)\n\t\t: undefined;\n\tconst failedChecks: GuardrailUserResult[] = [];\n\tconst passedChecks: GuardrailUserResult[] = [];\n\n\tconst handleFailedResults = (results: GroupedGuardrailResults): GuardrailUserResult[] => {\n\t\tconst unexpectedError = results.failed.find(\n\t\t\t(result) =>\n\t\t\t\tresult.status === 'rejected' ||\n\t\t\t\t(result.status === 'fulfilled' && result.value.executionFailed),\n\t\t);\n\n\t\tif (results.failed.length && operation === 'sanitize') {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Failed to sanitize text', {\n\t\t\t\tdescription: mapGuardrailErrorsToMessage(results.failed),\n\t\t\t\titemIndex,\n\t\t\t});\n\t\t}\n\t\tif (unexpectedError && !this.continueOnFail()) {\n\t\t\tconst error =\n\t\t\t\tunexpectedError.status === 'rejected'\n\t\t\t\t\t? unexpectedError.reason\n\t\t\t\t\t: unexpectedError.value.originalException;\n\t\t\tthrow new NodeOperationError(this.getNode(), error, {\n\t\t\t\tdescription: error?.description || error?.message,\n\t\t\t\titemIndex,\n\t\t\t});\n\t\t}\n\t\treturn results.failed.map(mapGuardrailResultToUserResult);\n\t};\n\n\tconst stageGuardrails: StageGuardRails = {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/process.ts#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: node operation = 'sanitize', input contains flagged PII\n// after: change node parameter operation to 'validate' to keep items and report status,\n// or narrow the PII guardrail entities list to the ones you actually want to block","handlingStrategy":"try-catch","validationCode":"// Pre-screen input against the same guardrails in 'validate' mode before running 'sanitize'.","typeGuard":null,"tryCatchPattern":"try {\n  await guardrailsNode.run({ operation: 'sanitize', ... });\n} catch (e) {\n  if (e.message === 'Failed to sanitize text') {\n    // route to a remediation branch instead of failing the workflow\n  } else throw e;\n}","preventionTips":["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."],"tags":["guardrails","sanitize","pii","node-operation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}