FlowiseAI/Flowise · warning · Error

Question and selectedChatModel are required

Error message

Question and selectedChatModel are required

What it means

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.

Source

Thrown at packages/server/src/controllers/agentflowv2-generator/index.ts:7

import { Request, Response, NextFunction } from 'express'
import agentflowv2Service from '../../services/agentflowv2-generator'

const generateAgentflowv2 = async (req: Request, res: Response, next: NextFunction) => {
    try {
        if (!req.body.question || !req.body.selectedChatModel) {
            throw new Error('Question and selectedChatModel are required')
        }
        const apiResponse = await agentflowv2Service.generateAgentflowv2(req.body.question, req.body.selectedChatModel)
        return res.json(apiResponse)
    } catch (error) {
        next(error)
    }
}

export default {
    generateAgentflowv2
}

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Ensure the client sends JSON body with non-empty 'question' (string) and 'selectedChatModel' (string) fields.
  2. Confirm express.json() or equivalent body-parsing middleware is mounted so req.body is populated.
  3. Disable the submit button until both fields have values.
  4. Upgrade the throw to an InternalFlowiseError with a 400/412 status for a correct HTTP response.

Example fix

// before
if (!req.body.question || !req.body.selectedChatModel) {
    throw new Error('Question and selectedChatModel are required')
}

// after: return a proper 400 instead of an opaque 500
if (!req.body?.question || !req.body?.selectedChatModel) {
    throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')
}
Defensive patterns

Strategy: validation

Validate before calling

function validateGenerateInput(body: any): asserts body is { question: string; selectedChatModel: string } {
    if (!body || typeof body.question !== 'string' || !body.question || typeof body.selectedChatModel !== 'string' || !body.selectedChatModel) {
        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')
    }
}
validateGenerateInput(req.body)

Type guard

function isGenerateInput(body: unknown): body is { question: string; selectedChatModel: string } {
    return typeof (body as any)?.question === 'string' && (body as any).question.length > 0
        && typeof (body as any)?.selectedChatModel === 'string' && (body as any).selectedChatModel.length > 0
}

Try / catch

// handler already wraps in try/catch and calls next(error); map it to 400:
try {
    if (!req.body?.question || !req.body?.selectedChatModel) {
        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Question and selectedChatModel are required')
    }
    const apiResponse = await agentflowv2Service.generateAgentflowv2(req.body.question, req.body.selectedChatModel)
    return res.json(apiResponse)
} catch (error) {
    next(error)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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