n8n-io/n8n · error · GuardrailError
Failed to parse output
Error message
Failed to parse output
What it means
Thrown by the Guardrails model helper inside its try/catch when the caught error is identified as a LangChain OutputParserException (isLangChainParserError returns true). It indicates the LLM output could not be parsed at all, as opposed to being parsed but malformed (which raises 'Invalid output format'). The description is the constant MODEL_OUTPUT_PARSER_ERROR_MESSAGE.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/model.ts:124
}
if (content[0].type === 'text') {
return content[0].text as string;
}
throw new Error('Invalid content type');
};
const text = extractText(result.content);
const { confidenceScore, flagged } = await outputParser.parse(text);
// Validate output consistency
if (typeof confidenceScore !== 'number' || typeof flagged !== 'boolean') {
throw new GuardrailError(name, 'Invalid output format', 'Expected number and boolean fields');
}
return { confidenceScore, flagged };
} catch (error) {
if (isLangChainParserError(error)) {
throw new GuardrailError(name, 'Failed to parse output', MODEL_OUTPUT_PARSER_ERROR_MESSAGE);
}
throw new GuardrailError(
name,
`Guardrail validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
error?.description,
);
}
}
export async function runLLMValidation(
name: string,
inputText: string,
{ model, prompt, threshold, systemMessage }: LLMConfig,
): Promise<GuardrailResult> {
try {
const result = await runLLM(name, model, prompt, inputText, systemMessage);
const triggered = result.flagged && result.confidenceScore >= threshold;
return {View on GitHub (pinned to 5ac6606e81)
Solutions
- Ensure the prompt includes and reinforces the required output format instructions.
- Upgrade or pin the langchain OutputParser so its parsing leniency matches what the model emits.
- Switch to a model with stronger instruction-following for structured output.
- If the model persistently wraps output in code fences, pre-strip fences before calling parse.
Example fix
// before: raw model output passed straight to parser text = extractText(result.content); // after: strip markdown fences before parsing text = extractText(result.content).replace(/^```(?:json)?|```$/g, '').trim();
Defensive patterns
Strategy: try-catch
Validate before calling
// Strip code fences and validate JSON before invoking the parser.
function preprocessModelOutput(text) {
return text.replace(/^```(?:json)?|```$/g, '').trim();
} Try / catch
try { ... } catch (e) {
if (isLangChainParserError(e)) {
// retry with a stricter prompt or a different model
} else throw e;
} Prevention
- Always include format instructions in the guardrail prompt.
- Pin langchain versions so parser behavior is stable.
- Pre-clean model output (strip fences, whitespace) before parsing.
When it happens
Trigger: outputParser.parse(text) throws an OutputParserException because the model output does not match the expected format at all (missing JSON, unparseable structure). The catch detects this specific error type and throws GuardrailError 'Failed to parse output'.
Common situations: Model returns natural-language prose instead of structured output; model wraps JSON in markdown fences the parser cannot strip; langchain OutputParser version change tightening parsing; prompt template not including the format instructions.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid output format
- LLM doesn't support binding tools
- Chat Model is required
- Guardrail validation failed: ${error instanceof Error ? erro
- Tool "${toolName}" was called but not found among connected
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/d3597d8d7e596c0c.
Report an issue: GitHub.