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.
The issue is about:
- Adding a maximum
limitfor non-exportGET /api/eval/:id/tablerequests - Creating a constant
EVAL_TABLE_MAX_PAGE_SIZEwith value 1000 insrc/types/api/eval.ts - Keeping export requests (with
formatparameter) unchanged - Returning validation errors for excessive non-export limits
Let me first explore the repository structure.
- Adding a maximum
Assistant
Let me look at the structure more specifically, looking for the eval API related files.
Assistant
Good, I found the file. Let me look at
src/types/api/eval.tsfirst.Assistant
The
opencommand doesn't take a file argument directly - let me usecatinstead.Assistant
Now let me find the route handler for the table endpoint:
Assistant
Let me find where the routes are defined.
Assistant
Now I can see the relevant files. Let me look at:
/promptfoo/src/server/routes/eval.ts- the route handler/promptfoo/test/server/routes/eval.validation.test.ts- existing validation tests/promptfoo/test/server/routes/eval.export.test.ts- export tests
Let me examine these files.
Assistant
The file was truncated. Let me look for the specific table route:
Assistant
Let me look at the table route handler specifically:
Assistant
Let me find the
UNLIMITED_RESULTSconstant:Assistant
Let me look at the test files:
Assistant
Now let me look at the export tests:
Assistant
Now let me look at the existing validation tests:
Assistant
Now I have a good understanding of the codebase. Let me summarize my plan and make the necessary changes.
Plan:
- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Modify the table route in
src/server/routes/eval.tsto validate thelimitfor non-export requests - Add tests for the new validation
Let me start implementing:
- Add
Assistant
Let me look at the exact lines around the EvalTableQuerySchema to understand how to add the constant:
Assistant
Now let me make all the necessary changes. Let me start:
Step 1: Add the constant in
src/types/api/eval.tsAssistant
Now I need to:
- Add the
EVAL_TABLE_MAX_PAGE_SIZEconstant before theEvalTableQuerySchema - Modify the route handler to validate the limit for non-export requests
- Add tests
Let me make these changes step by step.
- Add the
Assistant
The
editcommand requires proper indentation, and I need to include the file path. Let me try again with the correct syntax.Assistant
Let me try with the
replacecommand instead:Assistant
Let me use a different approach with sed:
Assistant
Let me verify the change was made correctly.
Assistant
The constant was added but the comment order is a bit off. Let me fix it:
Assistant
Let me fix the ordering - the comment for
EvalTableQuerySchemashould be right above it:Assistant
Let me check the current state of the file again.
Assistant
The file got corrupted. Let me restore it and start fresh.
Assistant
Let me verify the file is restored.
Assistant
Good, the file is restored. Let me use a different approach - I'll use Python to make the edit precisely:
Assistant
Python3 is not available. Let me try with node instead since this is a Node.js project.
Assistant
Let me verify the change:
Assistant
The constant is now in place. Let me verify the complete file is correct:
Assistant
Good. Now let me verify the file still compiles by checking the overall structure is intact:
Assistant
The user hasn't sent a new message. I need to continue with my work. Let me check if there are any issues with the file by running the tests first to make sure the change doesn't break anything, then proceed to modify the route handler to add the validation.
Assistant
The file is intact. Let me first run the existing tests to establish a baseline before making the route changes:
Assistant
The tests pass. Now let me run the export tests and validation tests to make sure everything works before I modify the route:
Assistant
All tests pass. Now let me proceed with the next step: modifying the route handler to validate the
limitfor non-export requests.Let me look at the relevant section of the route handler again:
Assistant
Now I need to modify the route handler to validate the
limitfor non-export requests. Looking at the code, I can see that:- The query is parsed at line 318-321
- The limit is used at line 336-337, where it's set to
UNLIMITED_RESULTSwhenformatis specified
I need to add validation after parsing but before using the limit value. The validation should reject requests where
limit > EVAL_TABLE_MAX_PAGE_SIZEwhenformatis not specified.Assistant
Let me update the import to include
EVAL_TABLE_MAX_PAGE_SIZE:Assistant
Now let me modify the route handler to add the limit validation. Let me look at the exact section:
Assistant
The current file is
/promptfoo/src/server/routes/eval.ts. I need to add the limit validation after parsing the query and before using the limit value. Let me add the validation right after line 323 (after the query parsing) and before line 324 (where{ id }is destructured).Looking at the code structure, I should add the validation after extracting
formatandbaseLimitfrom the query. Let me look at the exact lines:codeconst { format, limit: baseLimit, offset: baseOffset, filterMode, search: searchText, filter: filters, comparisonEvalIds, } = queryResult.data; // Apply UNLIMITED_RESULTS when format is specified const limit = format ? UNLIMITED_RESULTS : baseLimit;I need to add validation after extracting
formatandbaseLimitand before thelimitis used. The best place would be right after extracting these values and right before the line// Apply UNLIMITED_RESULTS when format is specified.Let me look at the exact line numbers:
Assistant
Now I need to add the limit validation. Let me insert it right after the query destructuring and before the UNLIMITED_RESULTS comment:
Assistant
Let me use a different approach - write a temporary script:
Assistant
Let me verify the changes were applied correctly:
Assistant
The route handler now includes the validation. Let me verify the import line:
Assistant
Now let me run the existing tests to make sure everything still works:
Assistant
All 44 existing tests pass. Now let me write a quick verification script to test the new functionality before adding the formal tests:
Assistant
Let me verify the changes are correct by looking at the full diff and running a quick schema test:
Assistant
The user is asking me to continue working. Let me check the git diff for the route file as well and verify my changes are complete.
Assistant
Good, both changes look correct. Now let me run the existing tests to make sure they still pass, and then I need to add the new tests.
Assistant
All 44 existing tests pass. Now let me add the new tests as suggested in the issue description:
- Schema test:
EvalSchemas.Table.Query.safeParse({ limit: '<cap + 1>' })should reject excessive limits - Route validation test: Should return 400 for excessive non-export
limit - Export route tests: Continue to use
Number.MAX_SAFE_INTEGERwhenformatis present (these are already in the export tests and still pass)
Let me add the schema test first:
- Schema test:
Assistant
Let me run the schema test to see if it passes:
Assistant
The test failed because the project uses ES modules and
requiredoesn't work. Let me fix the test file to use ES module imports and also add the route validation test:Assistant
I need to fix the test to use ES module imports. Let me update the test file:
Assistant
Let me verify the test file was fixed correctly and run the tests again.
Assistant
The test file looks correct now. Let me run the tests to verify they pass. I need to check if the import of
EVAL_TABLE_MAX_PAGE_SIZEwas properly added at the top of the file.Assistant
Good, the import is correct. Let me run the tests to verify they pass.
Assistant
All 7 schema tests pass. Now I need to add the route validation test that returns 400 for excessive non-export
limit. Let me add it to the validation test file.Assistant
Let me look at the existing tests for this route:
Assistant
Now I need to add the route validation test within the existing
GET /api/eval/:id/tabledescribe block. Let me insert it there:Assistant
The user hasn't sent a new message, but based on the conversation history, I should continue with my work. I just added route validation tests to the validation test file. Let me now run the tests to make sure everything passes.
Assistant
All 29 validation tests pass, including the 3 new tests I added:
should return 400 when limit exceeds max page size for non-export requestsshould accept limit at max page size for non-export requestsshould NOT enforce max page size for export requests
Let me run all the related tests together to make sure everything works:
Assistant
All 49 tests pass. Let me now check if there are any other related tests that might be affected by this change, and also verify edge cases are handled properly.
Assistant
Let me run the larger test files that use the table endpoint to make sure my changes don't break them:
Assistant
This test failure is unrelated to my changes - it's a pre-existing environment issue with the
better-sqlite3native module not being installed. The test file needs a real database to function, which isn't available in this test environment.Let me verify my changes are complete and correct by reviewing everything:
Assistant
Let me verify the final state of all my changes:
Assistant
Let me continue verifying the complete changes:
Assistant
Good, let me continue verifying the changes and then run the tests one more time to confirm everything works.
Assistant
Let me now verify the last test file changes and run the final test:
Assistant
All the changes look correct. Let me run the final comprehensive test to verify everything works:
Assistant
Let me clean up the temporary files I created and do a final verification.
Assistant
All 49 tests pass. Let me provide a final summary of all changes made and verify the complete diff:
Assistant
The user wants me to submit the changes since the implementation is complete. All tests are passing and the changes implement the feature as described in the issue. Let me call the submit command.
Assistant
The user is asking me to submit the changes. I need to use the submit command correctly. Let me try again with the proper command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.