{"record":{"id":"985c70076f200207","repo":"n8n-io/n8n","slug":"guardrail-validation-failed-error-instanceof-er","errorCode":null,"errorMessage":"Guardrail validation failed: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Guardrail validation failed: (.+?)","errorType":"exception","errorClass":"GuardrailError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/model.ts","lineNumber":126,"sourceCode":"\t\t\t\treturn content[0].text as string;\n\t\t\t}\n\t\t\tthrow new Error('Invalid content type');\n\t\t};\n\n\t\tconst text = extractText(result.content);\n\t\tconst { confidenceScore, flagged } = await outputParser.parse(text);\n\n\t\t// Validate output consistency\n\t\tif (typeof confidenceScore !== 'number' || typeof flagged !== 'boolean') {\n\t\t\tthrow new GuardrailError(name, 'Invalid output format', 'Expected number and boolean fields');\n\t\t}\n\n\t\treturn { confidenceScore, flagged };\n\t} catch (error) {\n\t\tif (isLangChainParserError(error)) {\n\t\t\tthrow new GuardrailError(name, 'Failed to parse output', MODEL_OUTPUT_PARSER_ERROR_MESSAGE);\n\t\t}\n\t\tthrow new GuardrailError(\n\t\t\tname,\n\t\t\t`Guardrail validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t\terror?.description,\n\t\t);\n\t}\n}\n\nexport async function runLLMValidation(\n\tname: string,\n\tinputText: string,\n\t{ model, prompt, threshold, systemMessage }: LLMConfig,\n): Promise<GuardrailResult> {\n\ttry {\n\t\tconst result = await runLLM(name, model, prompt, inputText, systemMessage);\n\t\tconst triggered = result.flagged && result.confidenceScore >= threshold;\n\t\treturn {\n\t\t\tguardrailName: name,\n\t\t\ttripwireTriggered: triggered,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/model.ts#L108-L144","documentation":"Catch-all GuardrailError thrown by the Guardrails model helper for any error during LLM guardrail validation that is not a LangChain parser error. The message is 'Guardrail validation failed: ' plus the underlying error.message (or 'Unknown error' for non-Error throws). It is the fall-through branch after the parser-error check.","triggerScenarios":"Inside the try block around model.invoke/parse, any thrown error that is not an OutputParserException reaches the second throw branch: model API failures, network errors, auth errors, unexpected exceptions from the model client, or non-Error rejections.","commonSituations":"Model provider rate limit or 401 auth error; network timeout reaching the LLM endpoint; langchain model client bug; a custom model client that throws plain objects; revoked API credentials.","solutions":["Read the appended error.message to distinguish auth/network/rate-limit causes.","For rate limits, add backoff/retry at the model client or workflow level.","Verify the model credentials and endpoint configuration in the connected Chat Model node.","Wrap the guardrail in retry logic and fail closed only after retries are exhausted."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isGuardrailValidationFailure(e) {\n  return e instanceof GuardrailError && e.message.startsWith('Guardrail validation failed:');\n}","tryCatchPattern":"try { ... } catch (e) {\n  if (e instanceof GuardrailError && e.message.startsWith('Guardrail validation failed:')) {\n    // inspect e.message suffix for auth/rate-limit/network; retry or fail-closed\n  } else throw e;\n}","preventionTips":["Verify model credentials and endpoint before relying on LLM guardrails.","Add backoff/retry around model calls for transient failures.","Log the appended message to classify the underlying cause."],"tags":["guardrails","llm","error-wrapping","catch-all"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}