{"record":{"id":"1512eda9d8aed6d8","repo":"FlowiseAI/Flowise","slug":"llm-response-is-missing-the-output-key-or-it-is","errorCode":null,"errorMessage":"LLM response is missing the \"output\" key or it is not a string.","messagePattern":"LLM response is missing the \"output\" key or it is not a string\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts","lineNumber":415,"sourceCode":"            if (analyticHandlers && llmIds) {\n                const analyticsOutput: any = {\n                    content: responseContent\n                }\n                // 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) => {","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/agentflow/ConditionAgent/ConditionAgent.ts#L397-L433","documentation":"After the LLM responds, ConditionAgent.parseJsonMarkdown parses the content and requires parsedResponse.output to be a truthy string — the matched scenario name. If output is missing, null, a number, or an object, the agent cannot pick a scenario and throws this. It is then caught locally and re-thrown as the 'Failed to parse a valid scenario' message (error 14).","triggerScenarios":"LLM returns valid JSON but with a different key (e.g. 'result', 'answer', 'scenario' instead of 'output'); output is a number/boolean; output is an empty string; output is an array of names instead of a single name.","commonSituations":"Model deviating from the few-shot schema; prompt override dropping the 'output' key requirement; model returning the scenario text under a key it guessed; structured-output schema drift.","solutions":["Reinforce in the system prompt that the JSON must contain an 'output' string key holding exactly one scenario name.","Keep the provided few-shot example (which shows {\"output\": \"...\"}).","Switch to a model with stronger instruction-following or native JSON mode.","If you control the LLM tool/structured schema, enforce an 'output' string property."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function extractScenarioOutput(parsed) {\n  if (!parsed || typeof parsed.output !== 'string' || parsed.output.length === 0) {\n    throw new Error('LLM JSON must contain a non-empty string \"output\" key')\n  }\n  return parsed.output\n}","typeGuard":"function hasStringOutput(parsed) {\n  return !!parsed && typeof parsed.output === 'string' && parsed.output.length > 0\n}","tryCatchPattern":"try { calledOutputName = extractScenarioOutput(parsedResponse) }\ncatch { /* re-prompt the model with stricter instructions */ }","preventionTips":["Keep the few-shot example showing {\"output\": \"...\"}.","Use structured-output / tool-calling to enforce the output schema.","Do not override the system prompt in a way that drops the 'output' key."],"tags":["condition-agent","llm-output","json-schema","structured-output"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}