{"record":{"id":"cef336bad02a1174","repo":"FlowiseAI/Flowise","slug":"invalid-evaluator-type","errorCode":null,"errorMessage":"Invalid evaluator type","messagePattern":"Invalid evaluator type","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/server/src/Interface.Evaluation.ts","lineNumber":109,"sourceCode":"                outputSchema: body.outputSchema\n            }\n        } else if (body.type === 'text') {\n            config = {\n                operator: body.operator,\n                value: body.value\n            }\n        } else if (body.type === 'json') {\n            config = {\n                operator: body.operator\n            }\n        } else if (body.type === 'numeric') {\n            config = {\n                operator: body.operator,\n                value: body.value,\n                measure: body.measure\n            }\n        } else {\n            throw new Error('Invalid evaluator type')\n        }\n        newDs.config = JSON.stringify(config)\n        return newDs\n    }\n\n    static fromEntity(entity: Evaluator): EvaluatorDTO {\n        const newDs = new EvaluatorDTO()\n        Object.assign(newDs, entity)\n        const config = JSON.parse(entity.config)\n        if (entity.type === 'llm') {\n            newDs.prompt = config.prompt\n            newDs.outputSchema = config.outputSchema\n        } else if (entity.type === 'text') {\n            newDs.operator = config.operator\n            newDs.value = config.value\n        } else if (entity.type === 'json') {\n            newDs.operator = config.operator\n            newDs.value = config.value","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/Interface.Evaluation.ts#L91-L127","documentation":"EvaluatorDTO.toEntity converts an inbound request body into an Evaluator entity by branching on body.type. Only four types are supported: 'llm', 'text', 'json', 'numeric'. Any other value (including undefined, wrong casing, or a typo) falls through every if/else-if branch and hits the terminal else, throwing 'Invalid evaluator type'. This guards the config JSON shape, since each type assembles different fields into config.","triggerScenarios":"POST/PUT to an evaluator endpoint with body.type set to an unsupported string (e.g. 'boolean', 'regex', 'LLM' uppercase, or omitted entirely). Importing or migrating evaluator records whose type field doesn't match the four canonical values. A client sending a new evaluator kind before the server supports it.","commonSituations":"Frontend dropdown sends a type the backend hasn't shipped support for yet. Casing mismatch ('Numeric' vs 'numeric'). Older exported evaluators using a deprecated type label. Programmatic client constructing payloads with a typo in the type field.","solutions":["Set body.type to exactly one of 'llm', 'text', 'json', 'numeric' (lowercase) before calling toEntity.","If the client legitimately needs a new evaluator type, extend the if/else chain and the fromEntity branch to handle it before sending that value.","Add request-level validation (e.g. a schema/enum check) at the controller so an invalid type is rejected with a clear 400 before reaching toEntity.","Sanitize/normalize imported evaluator type values to the canonical lowercase set during migration."],"exampleFix":"// before\nif (body.type === 'llm') { ... }\nelse if (body.type === 'text') { ... }\nelse if (body.type === 'json') { ... }\nelse if (body.type === 'numeric') { ... }\nelse { throw new Error('Invalid evaluator type') }\n\n// after: validate up front with an explicit allow-list\nconst VALID = ['llm', 'text', 'json', 'numeric'] as const\nif (!VALID.includes(body.type)) {\n    throw new Error(`Invalid evaluator type '${body.type}'. Expected one of: ${VALID.join(', ')}`)\n}","handlingStrategy":"validation","validationCode":"const EVALUATOR_TYPES = ['llm', 'text', 'json', 'numeric'] as const\ntype EvaluatorType = typeof EVALUATOR_TYPES[number]\n\nfunction assertEvaluatorType(type: unknown): asserts type is EvaluatorType {\n    if (!typeof type === 'string' || !(EVALUATOR_TYPES as readonly string[]).includes(type)) {\n        throw new Error(`Invalid evaluator type '${type}'. Expected one of: ${EVALUATOR_TYPES.join(', ')}`)\n    }\n}\n\n// in controller, before calling EvaluatorDTO.toEntity:\nassertEvaluatorType(req.body.type)","typeGuard":"function isEvaluatorType(type: unknown): type is 'llm' | 'text' | 'json' | 'numeric' {\n    return typeof type === 'string' && ['llm', 'text', 'json', 'numeric'].includes(type)\n}","tryCatchPattern":"try {\n    const entity = EvaluatorDTO.toEntity(req.body)\n} catch (err) {\n    if (err instanceof Error && err.message === 'Invalid evaluator type') {\n        return res.status(StatusCodes.BAD_REQUEST).json({ error: err.message, allowed: ['llm', 'text', 'json', 'numeric'] })\n    }\n    throw err\n}","preventionTips":["Validate type against an explicit allow-list at the controller boundary before reaching toEntity.","Drive the frontend dropdown from the same allow-list so only valid types are selectable.","Lowercase/normalize imported evaluator type values during migration.","Write unit tests covering each type branch plus the rejected case."],"tags":["validation","evaluator","typescript","input-validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}