{"record":{"id":"fab27b44bfb5130c","repo":"Mintplex-Labs/anything-llm","slug":"duplicate-rule-constraint-violated","errorCode":null,"errorMessage":"Duplicate rule constraint violated.","messagePattern":"Duplicate rule constraint violated\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/modelRouter.js","lineNumber":126,"sourceCode":"      }\n    }\n  );\n\n  app.post(\n    \"/model-routers/:id/rules/new\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {\n        const { id } = request.params;\n        const user = await userFromSession(request, response);\n        const data = reqBody(request);\n        const routerId = Number(id);\n        const { rule, error } = await ModelRouterRule.create(\n          routerId,\n          data,\n          user?.id || null\n        );\n        if (error) return response.status(400).json({ rule, error });\n\n        await Telemetry.sendTelemetry(\"model_router_rule_created\");\n        ModelRouterService.invalidateRouter(routerId);\n        return response.status(200).json({ rule });\n      } catch (e) {\n        console.error(e);\n        response.sendStatus(500);\n      }\n    }\n  );\n\n  app.put(\n    \"/model-routers/:id/rules/reorder\",\n    [validatedRequest, flexUserRoleValid([ROLES.admin])],\n    async (request, response) => {\n      try {\n        const { id } = request.params;\n        const { ruleUpdates } = reqBody(request);","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/modelRouter.js#L108-L144","documentation":"Constraint error propagated from ModelRouterRule.create: a database uniqueness constraint on the rule combination (e.g. title/priority per router) was violated despite prior checks, typically a race with a concurrent insert, and creation is refused.","triggerScenarios":"Thrown at server/endpoints/modelRouter.js:126 when the library encounters an invalid state.","commonSituations":"A unique constraint on (router, title) or (router, priority) was violated during rule creation/update.","solutions":["Change the rule title or priority so it is unique on this router.","Inspect the database constraint error for which field collided."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}