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 start by exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue description.
The issue is about:
- Adding a maximum
limitfor non-exportGET /api/eval/:id/tablerequests - Keeping exports (format=csv/json) unchanged
- Returning validation errors for excessive non-export limits
- Creating a constant
EVAL_TABLE_MAX_PAGE_SIZEwith value 1000 insrc/types/api/eval.ts
Let me first explore the repository structure.
- Adding a maximum
Assistant
Let me explore the specific file mentioned in the issue:
src/types/api/eval.tsAssistant
I need to use the correct syntax for the open command.
Assistant
Let me also look at the existing test file and the route handler:
Assistant
Now let me find the route handler for the eval table endpoint:
Assistant
Let me see the table endpoint specifically - I need to scroll to find the GET
/:id/tableroute:Assistant
Assistant
Now let me see where
UNLIMITED_RESULTSis defined and how the limit is used:Assistant
Now I understand the structure. Let me also look at the existing tests for the eval route validation:
Assistant
Now I have a clear picture of what needs to be done:
- Add a constant
EVAL_TABLE_MAX_PAGE_SIZE = 1000insrc/types/api/eval.ts - Add a
.max(1000)constraint on thelimitfield inEvalTableQuerySchema(for non-export requests) - The route handler already handles exports by checking
formatand usingUNLIMITED_RESULTS- but the schema validation happens before the route logic, so I need to think about this carefully.
Let me look at the route handler logic again more carefully:
- Add a constant
Assistant
The issue is: if I add
.max(1000)to the schema, it will reject export requests with limit > 1000. But export requests should bypass the limit cap.Looking at the route logic:
- Schema validates first
- Then route checks
formatand appliesUNLIMITED_RESULTSif format is present
So I need to handle this differently. The solution is:
- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Add the
.max(1000)constraint to the schema'slimitfield, but only whenformatis NOT present
There are a few ways to handle this:
- Option A: Use a Zod refinement that checks limit only when format is not present
- Option B: Create a separate validation in the route handler for non-export limits
- Option C: Use
.refine()in the schema to conditionally validate
Looking at the issue description more carefully:
- "schema test rejects
EvalSchemas.Table.Query.safeParse({ limit: '<cap + 1>' })"
This implies the schema itself should reject it when format is not present. Let me implement Option A using a refinement:
Assistant
Let me check how
prefaultworks - it's a custom extension:Assistant
grepreturned no output (exit code 0 but empty). Let me search more specifically for whereprefaultis defined.Assistant
It seems
prefaultis used like.default()- it's likely a custom zod extension or just an alias. For my purposes, I'll focus on the issue at hand. Let me check the exact approach used by looking at how other API schemas handle max constraints:Assistant
Now let me understand the approach. The issue description says:
- "schema test rejects
EvalSchemas.Table.Query.safeParse({ limit: '<cap + 1>' })"
But it also says:
- "Keep
format=csv/format=jsonexports unchanged so full-table exports still work as intended."
This is a bit tricky because the schema validation happens before the route handler. If I add
.max(1000)to the schema, it would also reject export requests.Let me re-read the issue more carefully... The suggestion says "schema test rejects" - meaning when you parse
{ limit: 1001 }WITHOUT aformat, it should fail. And when you have{ limit: 1001, format: 'csv' }, the export should still work.The cleanest approach is to use a
.refine()that checkslimitonly whenformatis not present. Let me implement this:- "schema test rejects
Assistant
Now I have a clear plan. I need to:
- Add the constant
EVAL_TABLE_MAX_PAGE_SIZE = 1000at the top of the file (or near the EvalTableQuerySchema) - Add a
.refine()toEvalTableQuerySchemathat validateslimit <= 1000only whenformatis not present - Export the constant
Let me implement this:
- Add the constant
Assistant
Now I'll implement the changes. First, let me add the constant and modify the schema:
Assistant
Now I'll make the changes. I need to:
- Add
EVAL_TABLE_MAX_PAGE_SIZEconstant before the schema - Add a
.refine()to enforce the limit cap when no format is specified
- Add
Assistant
Let me fix the replace syntax:
Assistant
Let me try a different approach using edit instead of replace.
Assistant
The changes look correct. Now let me create a test script to verify the changes work as expected:
Assistant
The script is in /tmp so it can't find the module. Let me put it in the project directory:
Assistant
I see the issue - my logic is backwards! The refine condition should allow any limit when
formatis present, and cap when it's absent. Let me fix the condition:Assistant
All tests pass. Now let me clean up the test file and run the existing tests to make sure I haven't broken anything:
Assistant
Existing tests pass. Let me also run the validation tests for the eval routes:
Assistant
All tests pass. Now let me run the export tests to make sure exports still work:
Assistant
Let me also run some other related tests:
Assistant
This test failure is not related to my changes - it's an environment/infrastructure issue with the database. Let me check a few more tests to make sure my changes don't break anything:
Assistant
The failures are due to a missing native module (
better-sqlite3), not my changes. The tests that can run without the database all pass (323 passed).Let me verify my changes once more by looking at the final state of the file:
Assistant
Let me also check that the
EVAL_TABLE_MAX_PAGE_SIZEconstant is properly exported by checking what's at the end of theEvalSchemasobject to see if it's exposed properly:Assistant
Good. The constant is exported. Now let me verify my changes with
git diff:Assistant
The changes look correct. Let me run one final verification to make sure all the tests that are relevant to this change pass:
Assistant
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npx vitest run --grep "table" 2>&1 | tail -50 </tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.