FlowiseAI/Flowise · error · Error

Failed to parse a valid scenario from the LLM's response. Pl

Error message

Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${responseContent}"

What it means

Wrapper catch around parseJsonMarkdown and the output-key check (error 13). Any parse failure or missing/non-string output is re-thrown as this message, including the raw LLM response for debugging. Seeing it means the LLM's answer could not be turned into a valid scenario decision.

Source

Thrown at packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts:419

                // Include usage metadata if available
                if (response.usage_metadata) {
                    analyticsOutput.usageMetadata = response.usage_metadata
                }
                // Include response metadata (contains model name) if available
                if (response.response_metadata) {
                    analyticsOutput.responseMetadata = response.response_metadata
                }
                await analyticHandlers.onLLMEnd(llmIds, analyticsOutput, { model: modelName, provider: model })
            }
            let calledOutputName: string
            try {
                const parsedResponse = this.parseJsonMarkdown(responseContent)
                if (!parsedResponse.output || typeof parsedResponse.output !== 'string') {
                    throw new Error('LLM response is missing the "output" key or it is not a string.')
                }
                calledOutputName = parsedResponse.output
            } catch (error) {
                throw new Error(
                    `Failed to parse a valid scenario from the LLM's response. Please check if the model is capable of following JSON output instructions. Raw LLM Response: "${responseContent}"`
                )
            }

            // Clean up empty inputs
            for (const key in nodeData.inputs) {
                if (nodeData.inputs[key] === '') {
                    delete nodeData.inputs[key]
                }
            }

            const matchedScenarioIndex = findBestScenarioIndex(_conditionAgentScenarios, calledOutputName)

            const conditions = _conditionAgentScenarios.map((scenario, index) => {
                return {
                    output: scenario.scenario,
                    isFulfilled: index === matchedScenarioIndex
                }

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Inspect the raw response in the error message to see what the model actually returned.
  2. If malformed JSON: lower temperature, increase max_tokens, use jsonrepair, or switch to a JSON-capable model.
  3. If wrong key/shape: reinforce the {"output": "<scenario>"} schema in the prompt and few-shot.
  4. If no JSON at all: re-add the JSON requirement to the (possibly overridden) system prompt.
Defensive patterns

Strategy: try-catch

Validate before calling

import { jsonrepair } from 'jsonrepair'
function robustScenarioParse(responseContent) {
  let parsed
  try { parsed = parseJsonMarkdown(responseContent) }
  catch {
    try { parsed = JSON.parse(jsonrepair(extractBraceBlock(responseContent))) }
    catch { return null }
  }
  if (!hasStringOutput(parsed)) return null
  return parsed.output
}

Type guard

function hasStringOutput(parsed) {
  return !!parsed && typeof parsed.output === 'string' && parsed.output.length > 0
}

Try / catch

let out = robustScenarioParse(responseContent)
if (!out) {
  // retry the LLM call once with a stricter prompt; if still failing, surface the raw response
} else { calledOutputName = out }

Prevention

When it happens

Trigger: parseJsonMarkdown throws 'Invalid JSON object' (error 9) or 'Could not find JSON block' (error 10), or the output key check (error 13) throws. The raw responseContent is interpolated, so the message shows exactly what the model returned.

Common situations: Weak model ignoring formatting instructions; truncated JSON from max_tokens; prompt override removing the JSON requirement; temperature too high; model returning prose instead of JSON.

Understand the failure class

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/5e17f240e4464623. Report an issue: GitHub.