ISSUE DESCRIPTION Cap eval table page size for non-export requests Summary GET…
- User
ISSUE DESCRIPTION
Cap eval table page size for non-export requests
Summary
GET /api/eval/:id/tableaccepts any positive integer forlimiton normal table requests. The route already intentionally treats export requests differently by usingNumber.MAX_SAFE_INTEGERwhenformatis set, but non-export page requests currently do not have an upper bound.Why this matters
A very large
limitcan make a normal table request ask the server to load and serialize a large amount of eval result data in one response. Other list-style APIs in the server already bound their page sizes, so the eval table endpoint should follow the same resource-control pattern.Proposed change
- Add a maximum
limitfor non-exportGET /api/eval/:id/tablerequests. - Keep
format=csv/format=jsonexports unchanged so full-table exports still work as intended. - Return validation errors for excessive non-export limits, consistent with nearby API schema validation.
A cap of
500or1000would likely cover normal UI usage while preventing accidental oversized page requests.Validation
Suggested tests:
- schema test rejects
EvalSchemas.Table.Query.safeParse({ limit: '<cap + 1>' }) - route validation test returns
400for excessive non-exportlimit - export route tests continue to use
Number.MAX_SAFE_INTEGERwhenformatis present
Interface
Type: Constant Name: EVAL_TABLE_MAX_PAGE_SIZE Path: src/types/api/eval.ts Value/Type: constant literal value 1000 (number) Description: Server-enforced upper bound for the
limitparameter on non-export eval table page requests. Exports usingformat(csv/json) are exempt from this cap; UI pagination controls derive their available page-size options from this value.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Add a maximum
Assistant
Let me analyze the issue:
- The endpoint
GET /api/eval/:id/tableaccepts any positive integer forlimiton normal table requests - Export requests already use
Number.MAX_SAFE_INTEGERwhenformatis set - Need to add a maximum
limit(1000) for non-export requests - Need to define
EVAL_TABLE_MAX_PAGE_SIZEconstant insrc/types/api/eval.ts - Need to add validation to reject limits exceeding the cap
- Exports should remain unchanged
Let me start by exploring the repository structure to understand the codebase.
- The endpoint
Assistant
Let me start by exploring the repository structure more carefully, especially looking for the eval-related files mentioned in the issue.
Assistant
Let me look at the src/types/api/eval.ts file mentioned in the issue, and also find the API route for eval table.
Assistant
The issue description mentions
src/types/api/eval.tswhich is the file I found. Let me open it to understand its current structure.Assistant
Let me try the correct syntax for the open command.
Assistant
Good, now I can see the eval.ts file. Let me find the route handler for the eval table endpoint to understand how the limit is currently used.
Assistant
Let me look at the route handler for eval table:
Assistant
Let me search for the table endpoint handler specifically:
Assistant
Let me see the full table route handler starting from line 311:
Assistant
Now I can see the table route handler. I can see:
- The
limitcomes frombaseLimitin the query - When
formatis specified (export), it usesUNLIMITED_RESULTS - For non-export requests, it uses
baseLimitdirectly without any upper bound
Let me check what
UNLIMITED_RESULTSis:- The
Assistant
Now I understand the current code. The issue is:
- Line 309 defines
UNLIMITED_RESULTS = Number.MAX_SAFE_INTEGER - Line 337: When
formatis present,limitbecomesUNLIMITED_RESULTS - When
formatis NOT present (normal table page requests),limitusesbaseLimitdirectly with no cap
I need to:
- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Add validation to the schema for the
limitfield (with conditional logic based on format) - Update the route to enforce the cap for non-export requests
Let me also look at how other APIs in the server enforce page size limits:
- Line 309 defines
Assistant
Let me look at how validation errors are returned in the route to understand the pattern:
Assistant
Now let me look at existing tests for the eval table to understand the testing patterns:
Assistant
Continue exploring the test files to understand the testing patterns.
Assistant
Now I have a good understanding of the codebase. Let me also check the export tests to understand how export routes are tested:
Assistant
Assistant
Good,
.superRefine()is used in the codebase. Let me use that for conditional validation. Now let me implement the changes:- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Add conditional validation using
.superRefine()to reject limit > 1000 when format is not present - Export the constant so it can be used elsewhere
Let me first check what's exported from the eval.ts file:
- Add
Assistant
Now I have a clear plan. Let me implement the changes:
- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant at the top ofsrc/types/api/eval.ts - Add conditional validation using
.superRefine()on theEvalTableQuerySchemato check thatlimit <= 1000whenformatis not present
Let me make the changes to
src/types/api/eval.ts:- Add
Assistant
Now let me add the constant and modify the schema. First, let me add the constant after the imports:
Assistant
I'll add the constant after the imports (after line 3):
Assistant
Let me verify the constant was added:
Assistant
Now let me find the EvalTableQuerySchema and add the superRefine validation. Let me check the current line numbers:
Assistant
Now I need to modify the
EvalTableQuerySchemato add the conditional validation using.superRefine(). The validation should check that whenformatis not set,limitshould not exceedEVAL_TABLE_MAX_PAGE_SIZE.Let me replace the schema definition:
Assistant
Now I need to replace the schema in the file. Let me use edit to do this:
Assistant
The changes look good. Now let me verify the file is correct by checking the relevant parts:
Assistant
The changes look good. Now let me create a test script to verify the changes work correctly:
Assistant
Let me fix the test script with the correct path:
Assistant
All tests pass. Let me clean up the test file:
Assistant
Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All existing validation tests pass. Let me also run the export tests to make sure exports still work:
Assistant
All export tests pass. Let me also run a broader set of tests related to the eval routes to make sure everything works:
Assistant
This test failure appears to be a pre-existing environment issue (not related to my changes) - the error is about server setup, not schema validation. Let me run the routes-eval.test.ts to verify my changes don't break the broader test suite:
Assistant
Let me also check if there are any other tests that might be affected by the schema change:
Assistant
Let me check this test file to see if my changes might affect it:
Assistant
Let me run this test to confirm it passes:
Assistant
All tests pass. Let me verify the final state of the file:
Assistant
The changes look good. Let me now verify the changes with git diff:
Assistant
Let me verify by looking at the current state of things and confirming everything works as expected.
Let me also run a broader set of tests related to eval to make sure nothing is broken.
Let me verify by looking at the current state of things and confirming everything works as expected. Let me also run a broader set of tests related to eval to make sure nothing is broken.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npx vitest run test/server/routes/eval 2>&1 | tail -40 </tool_call>
Assistant
I need to properly format my command call. Let me use the bash_terminal function correctly.
Assistant
The test failure in
eval.filteredMetrics.test.tsis a pre-existing environment issue (database bindings), not related to my changes. The key tests pass:eval.validation.test.ts: 26 tests passed ✓eval.export.test.ts: 13 tests passed ✓apiSchemas.redteam.test.ts: 28 tests passed ✓
Let me verify my changes align with the issue requirements one more time:
Assistant
I've completed the implementation for capping eval table page size for non-export requests. Here's a summary:
Changes Made
File:
src/types/api/eval.ts-
Added constant
EVAL_TABLE_MAX_PAGE_SIZE = 1000(line 6)- Server-enforced upper bound for the
limitparameter on non-export eval table page requests - Exported for use by UI pagination controls
- Server-enforced upper bound for the
-
Added conditional validation to (lines 103-110)
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.