{"record":{"id":"a66840d41668e724","repo":"FlowiseAI/Flowise","slug":"question-and-selectedchatmodel-are-required","errorCode":null,"errorMessage":"Question and selectedChatModel are required","messagePattern":"Question and selectedChatModel are required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/server/src/controllers/agentflowv2-generator/index.ts","lineNumber":7,"sourceCode":"import { Request, Response, NextFunction } from 'express'\nimport agentflowv2Service from '../../services/agentflowv2-generator'\n\nconst generateAgentflowv2 = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (!req.body.question || !req.body.selectedChatModel) {\n            throw new Error('Question and selectedChatModel are required')\n        }\n        const apiResponse = await agentflowv2Service.generateAgentflowv2(req.body.question, req.body.selectedChatModel)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nexport default {\n    generateAgentflowv2\n}\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/agentflowv2-generator/index.ts#L1-L19","documentation":"The agentflowv2-generator controller's single handler validates that the request body contains both question and selectedChatModel before delegating to the generator service. If either is falsy, a generic Error is thrown and passed to next(), becoming a 500 unless an error handler maps it. Both fields are required inputs for the LLM generation call.","triggerScenarios":"POST to the agentflowv2 generate endpoint with a body missing question, missing selectedChatModel, or with either set to empty string/null. Client sends only one of the two fields, or a malformed/empty JSON body.","commonSituations":"Frontend form submitted with an empty prompt field. selectedChatModel not yet chosen by the user. Programmatic client constructing the payload incompletely. Body-parsing middleware misconfigured so req.body is undefined.","solutions":["Ensure the client sends JSON body with non-empty 'question' (string) and 'selectedChatModel' (string) fields.","Confirm express.json() or equivalent body-parsing middleware is mounted so req.body is populated.","Disable the submit button until both fields have values.","Upgrade the throw to an InternalFlowiseError with a 400/412 status for a correct HTTP response."],"exampleFix":"// before\nif (!req.body.question || !req.body.selectedChatModel) {\n    throw new Error('Question and selectedChatModel are required')\n}\n\n// after: return a proper 400 instead of an opaque 500\nif (!req.body?.question || !req.body?.selectedChatModel) {\n    throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')\n}","handlingStrategy":"validation","validationCode":"function validateGenerateInput(body: any): asserts body is { question: string; selectedChatModel: string } {\n    if (!body || typeof body.question !== 'string' || !body.question || typeof body.selectedChatModel !== 'string' || !body.selectedChatModel) {\n        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')\n    }\n}\nvalidateGenerateInput(req.body)","typeGuard":"function isGenerateInput(body: unknown): body is { question: string; selectedChatModel: string } {\n    return typeof (body as any)?.question === 'string' && (body as any).question.length > 0\n        && typeof (body as any)?.selectedChatModel === 'string' && (body as any).selectedChatModel.length > 0\n}","tryCatchPattern":"// handler already wraps in try/catch and calls next(error); map it to 400:\ntry {\n    if (!req.body?.question || !req.body?.selectedChatModel) {\n        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')\n    }\n    const apiResponse = await agentflowv2Service.generateAgentflowv2(req.body.question, req.body.selectedChatModel)\n    return res.json(apiResponse)\n} catch (error) {\n    next(error)\n}","preventionTips":["Send both 'question' and 'selectedChatModel' as non-empty strings in the JSON body.","Disable the submit button until both fields have values.","Ensure express.json() middleware is mounted so req.body is parsed.","Upgrade the generic Error to an InternalFlowiseError with a 400 status for correct HTTP semantics."],"tags":["validation","controller","agentflow","input-validation","express"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}