{"record":{"id":"5e17f240e4464623","repo":"FlowiseAI/Flowise","slug":"failed-to-parse-a-valid-scenario-from-the-llm-s-re","errorCode":null,"errorMessage":"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}\"","messagePattern":"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: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts","lineNumber":419,"sourceCode":"                // Include usage metadata if available\n                if (response.usage_metadata) {\n                    analyticsOutput.usageMetadata = response.usage_metadata\n                }\n                // Include response metadata (contains model name) if available\n                if (response.response_metadata) {\n                    analyticsOutput.responseMetadata = response.response_metadata\n                }\n                await analyticHandlers.onLLMEnd(llmIds, analyticsOutput, { model: modelName, provider: model })\n            }\n            let calledOutputName: string\n            try {\n                const parsedResponse = this.parseJsonMarkdown(responseContent)\n                if (!parsedResponse.output || typeof parsedResponse.output !== 'string') {\n                    throw new Error('LLM response is missing the \"output\" key or it is not a string.')\n                }\n                calledOutputName = parsedResponse.output\n            } catch (error) {\n                throw new Error(\n                    `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}\"`\n                )\n            }\n\n            // Clean up empty inputs\n            for (const key in nodeData.inputs) {\n                if (nodeData.inputs[key] === '') {\n                    delete nodeData.inputs[key]\n                }\n            }\n\n            const matchedScenarioIndex = findBestScenarioIndex(_conditionAgentScenarios, calledOutputName)\n\n            const conditions = _conditionAgentScenarios.map((scenario, index) => {\n                return {\n                    output: scenario.scenario,\n                    isFulfilled: index === matchedScenarioIndex\n                }","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts#L401-L437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the raw response in the error message to see what the model actually returned.","If malformed JSON: lower temperature, increase max_tokens, use jsonrepair, or switch to a JSON-capable model.","If wrong key/shape: reinforce the {\"output\": \"<scenario>\"} schema in the prompt and few-shot.","If no JSON at all: re-add the JSON requirement to the (possibly overridden) system prompt."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { jsonrepair } from 'jsonrepair'\nfunction robustScenarioParse(responseContent) {\n  let parsed\n  try { parsed = parseJsonMarkdown(responseContent) }\n  catch {\n    try { parsed = JSON.parse(jsonrepair(extractBraceBlock(responseContent))) }\n    catch { return null }\n  }\n  if (!hasStringOutput(parsed)) return null\n  return parsed.output\n}","typeGuard":"function hasStringOutput(parsed) {\n  return !!parsed && typeof parsed.output === 'string' && parsed.output.length > 0\n}","tryCatchPattern":"let out = robustScenarioParse(responseContent)\nif (!out) {\n  // retry the LLM call once with a stricter prompt; if still failing, surface the raw response\n} else { calledOutputName = out }","preventionTips":["Use a model with strong JSON adherence for the Condition Agent.","Lower temperature and raise max_tokens for this node.","Log raw LLM responses to diagnose recurring parse failures."],"tags":["condition-agent","llm-output","parsing","catch-all"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}