{"record":{"id":"8233eafe38451553","repo":"Budibase/budibase","slug":"limit-query-must-be-between-1-and-100-8233ea","errorCode":null,"errorMessage":"Limit query must be between 1 and 100","messagePattern":"Limit query must be between 1 and 100","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/agentRequests.ts","lineNumber":24,"sourceCode":"  type UserCtx,\n} from \"@budibase/types\"\nimport sdk from \"../../../sdk\"\n\nconst DEFAULT_LIMIT = 100\n\nconst sanitizeLimitQuery = (limit?: string): number => {\n  const normalizedLimit = limit?.trim()\n  if (!normalizedLimit) {\n    return DEFAULT_LIMIT\n  }\n\n  if (!/^\\d+$/.test(normalizedLimit)) {\n    throw new HTTPError(\"Invalid limit query\", 400)\n  }\n\n  const parsedLimit = Number.parseInt(normalizedLimit, 10)\n  if (parsedLimit < 1 || parsedLimit > 100) {\n    throw new HTTPError(\"Limit query must be between 1 and 100\", 400)\n  }\n\n  return parsedLimit\n}\n\nconst sanitizePageQuery = (page?: string): number => {\n  const normalizedPage = page?.trim()\n  if (!normalizedPage) {\n    return 1\n  }\n\n  if (!/^\\d+$/.test(normalizedPage)) {\n    throw new HTTPError(\"Invalid page query\", 400)\n  }\n\n  const parsedPage = Number.parseInt(normalizedPage, 10)\n  if (parsedPage < 1) {\n    throw new HTTPError(\"Page query must be greater than 0\", 400)","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentRequests.ts#L6-L42","documentation":"Thrown by sanitizeLimitQuery when the limit is numeric but outside the allowed range. The library clamps valid requests to between 1 and 100 inclusive; parsed values below 1 or above 100 are rejected with this 400 error.","triggerScenarios":"GET agent requests with ?limit=0, ?limit=-3, or ?limit=500. Values like 101+ are digits so pass the regex but fail the range check.","commonSituations":"'Fetch everything' attempts using very large limits; UI spinners allowing 0 or negative page sizes; defaults copied from another API with different maxima; attempts to disable pagination by passing a huge limit.","solutions":["Use a limit between 1 and 100, e.g. ?limit=100","Omit the limit parameter to use DEFAULT_LIMIT","Clamp the value client-side: Math.min(100, Math.max(1, value))","Page through results using the page/bookmark parameters instead of raising limit"],"exampleFix":"// before\n?limit=500\n// after\n?limit=100","handlingStrategy":"validation","validationCode":"function clampLimit(limit, { min = 1, max = 100 } = {}) {\n  const n = Number.parseInt(String(limit), 10)\n  if (Number.isNaN(n)) return undefined\n  return Math.min(max, Math.max(min, n))\n}\nclampLimit(searchParams.get(\"limit\"))","typeGuard":"function isLimitInRange(v) {\n  return typeof v === \"number\" && Number.isInteger(v) && v >= 1 && v <= 100\n}","tryCatchPattern":"try {\n  return await fetchAgentRequests(agentId, { limit })\n} catch (err) {\n  if (err.status === 400 && err.message === \"Limit query must be between 1 and 100\") {\n    return fetchAgentRequests(agentId, { limit: 100 })\n  }\n  throw err\n}","preventionTips":["Clamp page-size values to 1-100 in the UI component itself","Do not attempt to 'fetch all' with a giant limit; use pagination","Align client defaults with the server's documented maximum","Add client-side validation mirroring server rules"],"tags":["validation","http-400","pagination","query-params"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}