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 for implementing this change.
The issue is about:
- Adding a maximum
limitfor non-exportGET /api/eval/:id/tablerequests - Adding a constant
EVAL_TABLE_MAX_PAGE_SIZEwith value 1000 - The constant should be in
src/types/api/eval.ts - Export requests (format=csv/json) should be exempt from this cap
- Return validation errors for excessive non-export limits
Let me first explore the repository structure and find the relevant files.
- Adding a maximum
Assistant
Let me find the file mentioned in the issue -
src/types/api/eval.ts<tool_call> <function=bash_terminal> <parameter=command> ls -la /promptfoo/src/types/api/ </tool_call>
Assistant
Let me try to explore the src directory to find the eval.ts file.
Assistant
Good, I found the eval.ts file. Let me open it to see its current contents.
<tool_call> <function=open> <parameter=file> /promptfoo/src/types/api/eval.ts </tool_call>
Assistant
I need to use the open command properly to view the eval.ts file.
Assistant
Now let me look at the route handler for the
/api/eval/:id/tableendpoint to understand how it's currently implemented. Let me search for the API route files.<tool_call> <function=bash_terminal> <parameter=command> find /promptfoo -type f -name ".ts" -path "/routes/*" | head -30 </tool_call>
Assistant
Let me search for route files related to eval endpoints.
Assistant
Great, there's an
eval.tsroute file. Let me open it to see how the/api/eval/:id/tableendpoint is handled.<tool_call> <function=bash_terminal> <parameter=command> cat /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
I need to use a tool call to view the file content. Let me use bash_terminal to cat the file.
Assistant
The output was truncated. Let me look for the specific table endpoint that I need to modify. Let me search for the GET endpoint for
/api/eval/:id/table.<tool_call> <function=bash_terminal> <parameter=command> grep -n "table" /promptfoo/src/server/routes/eval.ts | head -50 </tool_call>
Assistant
Let me use grep to find the table endpoint in the eval.ts route file.
Assistant
Let me look at the table endpoint around line 311 in detail.
Assistant
Now I can see the table endpoint. I see at line 333-334 that there's a reference to
UNLIMITED_RESULTS:const limit = format ? UNLIMITED_RESULTS : baseLimit; const offset = format ? 0 : baseOffset;Let me find where
UNLIMITED_RESULTSis defined.<tool_call> <function=bash_terminal> <parameter=command> grep -n "UNLIMITED_RESULTS" /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
I need to use a proper command. Let me use bash_terminal to search for UNLIMITED_RESULTS.
Assistant
I see the pattern now. The code uses
UNLIMITED_RESULTSfor exports and allows any positive integer for regular requests. Let me search for similar patterns in the codebase to understand how other APIs handle page size limits.Assistant
Now let me look for how other APIs handle page limits in this codebase to follow the same pattern.
Assistant
Let me look at the blobs.ts route to see how they handle pagination limits there.
Assistant
Let me look at the BlobsSchemas.Library.Query schema to see how they handle the limit parameter.
<tool_call> <function=bash_terminal> <parameter=command> cat /promptfoo/src/types/api/blobs.ts </tool_call>
Assistant
Let me use bash to read the blobs.ts file to see how the limit parameter is handled there.
Assistant
Assistant
Let me search for test files that contain "eval" in their content.
Assistant
Let me search for server route tests.
Assistant
Let me look at the test file for the eval routes to understand the testing pattern.
Assistant
Let me also check the test types for api schemas to understand how they're tested.
<tool_call> <function=bash_terminal> <parameter=command> ls /promptfoo/test/types/api/ </tool_call>
Assistant
I need to run a bash command to list the directory. Let me use bash_terminal.
Assistant
Let me read the eval.test.ts file to understand how eval schema tests are structured.
Assistant
Now I understand the codebase. Let me implement the changes:
- Add
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant to/promptfoo/src/types/api/eval.ts - Update the route handler to validate the limit for non-export requests
Let me start by updating the eval.ts types file to add the constant:
- Add
Assistant
Now let me implement the changes. First, I'll add the
EVAL_TABLE_MAX_PAGE_SIZEconstant to the eval.ts types file:Assistant
Let me verify the constant was added correctly:
Assistant
I see there's a slight formatting issue - the "Eval ID parameter schema." comment is now orphaned. Let me fix this by reorganizing the file properly:
<tool_call> <function=bash_terminal> <parameter=command> head -10 /promptfoo/src/types/api/eval.ts </tool_call>
Assistant
Let me use bash to see what happened with the file formatting:
Assistant
The sed command had an issue. Let me reset the file and fix it properly:
Assistant
Now let me properly add the constant. First, let me look at the current structure again:
Assistant
Let me use a more reliable approach to edit the file:
Assistant
Let me try with python instead of python3:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/add_constant.py << 'EOF' import re
with open('/promptfoo/src/types/api/eval.ts', 'r') as f: content = f.read()
Find the location after the imports
pattern = r"(import.from.\n)+import.from.\n" match = re.search(pattern, content, re.DOTALL) if match: insert_pos = match.end() new_content = content[:insert_pos] + """ /**
-
Server-enforced upper bound for the limit parameter on non-export eval table page requests.
-
Exports using format (csv/json) are exempt from this cap. */ export const EVAL_TABLE_MAX_PAGE_SIZE = 1000; """ + content[insert_pos:]
with open('/promptfoo/src/types/api/eval.ts', 'w') as f: f.write(new_content) print("Constant added successfully") else: print("Could not find insertion point") EOF python /tmp/add_constant.py
-
Assistant
Let me try using sed to insert the constant after the imports section. Let me first check if sed is available.
Assistant
Let me use a more reliable approach - I'll use sed to insert the constant after line 3 (after the third import line).
<tool_call> <function=bash_terminal> <parameter=command> sed -i '3a
/**\- Server-enforced upper bound for the limit parameter on non-export eval table page requests.\
- Exports using format (csv/json) are exempt from this cap.
*/
export const EVAL_TABLE_MAX_PAGE_SIZE = 1000;' /promptfoo/src/types/api/eval.ts
Assistant
Let me try a different approach using awk:
Assistant
Let me verify the constant was added correctly:
Assistant
The constant has been added correctly. Now I need to:
- Modify the route handler to validate the limit parameter for non-export requests
- Export the constant in the EvalSchemas if needed
Let me first look at the route handler to see how to add the validation:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '311,345p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me use bash to view the route handler lines.
Assistant
Now I can see the route handler structure. I need to:
- Import the
EVAL_TABLE_MAX_PAGE_SIZEconstant - Add validation after the query parsing to check if
limit > EVAL_TABLE_MAX_PAGE_SIZEwhenformatis not set
Let me first check the import section of the eval.ts route file:
<tool_call> <function=bash_terminal> <parameter=command> head -35 /promptfoo/src/server/routes/eval.ts </tool_call>
- Import the
Assistant
I need to use a proper bash_terminal command to see the file. Let me try again.
Assistant
Now I need to:
- Add the import for
EVAL_TABLE_MAX_PAGE_SIZEfrom the types file - Add validation after line 337 to check if the limit exceeds the max for non-export requests
Let me first update the import:
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/import { EvalSchemas } from/import { EvalSchemas, EVAL_TABLE_MAX_PAGE_SIZE } from/' /promptfoo/src/server/routes/eval.ts </tool_call>
- Add the import for
Assistant
Let me use the proper bash command to update the import.
Assistant
The sed command ran successfully. Now let me verify the import was updated correctly:
<tool_call> <function=bash_terminal> <parameter=command> head -15 /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me use a proper bash command to check the file.
Assistant
The import has been updated successfully. Now I need to add validation logic in the route handler to check if the limit exceeds the max for non-export requests. Let me add the validation after the query parsing but before extracting the values.
Let me find the exact line numbers where I need to add the validation:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '318,340p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me try a different approach to view the file lines.
Assistant
Now I need to add validation after line 321 (after the query parsing) and before line 323 (const { id } = ...). I'll add the validation that checks if limit exceeds the max for non-export requests.
<tool_call> <function=bash_terminal> <parameter=command> awk 'NR==322 { print " // Validate limit for non-export requests\n if (!queryResult.data.format && baseLimit > EVAL_TABLE_MAX_PAGE_SIZE) {\n res.status(400).json({ error:
limit exceeds maximum allowed value of ${EVAL_TABLE_MAX_PAGE_SIZE} for non-export requests});\n return;\n }"; } 1' /promptfoo/src/server/routes/eval.ts > /tmp/eval_route_new.ts && mv /tmp/eval_route_new.ts /promptfoo/src/server/routes/eval.ts </tool_call>Assistant
The awk command failed. Let me check what went wrong.
Looking at the command again:
awk 'NR==322 { print " // Validate limit for non-export requests\n if (!queryResult.data.format && baseLimit > EVAL_TABLE_MAX_PAGE_SIZE) {\n res.status(400).json({ error: `limit exceeds maximum allowed value of ${EVAL_TABLE_MAX_PAGE_SIZE} for non-export requests` });\n return;\n }"; } 1' /promptfoo/src/server/routes/eval.ts > /tmp/eval_route_new.ts && mv /tmp/eval_route_new.ts /promptfoo/src/server/routes/eval.tsThe issue is that the awk command is trying to use NR==322, but the insertion point might be different. Let me check what's on line 322.
Actually, looking at my previous output:
318: const queryResult = EvalSchemas.Table.Query.safeParse(req.query); 319: if (!queryResult.success) { 320: res.status(400).json({ error: z.prettifyError(queryResult.error) }); 321: return; 322: } 323: 324: const { id } = paramsResult.data;So line 322 is
}and I want to insert after that. But the awk command syntax might be wrong. Let me try a different approach.Actually, I realize the awk command seems to have run without error (exit code 0), so let me check if the file was modified.
Assistant
The file wasn't modified. Let me try a different approach using sed with a pattern match instead of a line number.
Assistant
This approach is getting complicated. Let me just check the file and use a simpler method - I'll create a Python script to do the edit.
Let me first check if the file was modified by looking at the relevant section.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '315,350p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
The sed command seems to have executed, but let me verify if the file was modified correctly. Let me check the file content again.
Assistant
The validation was added, but there's an issue - the
baseLimitvariable is defined after the validation block. Let me fix this by moving the validation after the destructuring.Assistant
The validation is in the wrong place -
baseLimitis destructured later. Let me fix this by moving the validation after the destructuring.Assistant
I need to fix the placement of the validation. The
baseLimitvariable is destructured later, so the validation is in the wrong place. Let me reset the file and make the edit correctly:Assistant
The file was reset. Now let me re-apply the import change and make a correct placement of the validation.
First, let me add the import again:
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/import { EvalSchemas } from/import { EvalSchemas, EVAL_TABLE_MAX_PAGE_SIZE } from/' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
The sed command ran without error. Now I need to add the validation in the correct place - after the destructuring of
baseLimitfromqueryResult.data.Let me find the correct line number where I should add the validation - after line 337 where
baseLimitis destructured.Assistant
Good, line 335 is
} = queryResult.data;and line 336 is empty. I want to add the validation after line 335 (after the destructuring). Let me use sed to insert after line 335.Assistant
The sed command ran successfully. Let me verify the changes:
Assistant
The validation has been added. However, I notice there's a missing blank line before the comment "Apply UNLIMITED_RESULTS". Let me fix that formatting issue and verify the entire change is correct.
Now I also need to:
- Make sure the constant is exported properly in the types file
- Check if there are any tests that need to be verified
Let me first verify the import in the route file:
<tool_call> <function=bash_terminal> <parameter=command> head -15 /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
I need to use a proper bash command to view the file.
Assistant
Hmm, the import change doesn't seem to have been applied. The sed command might have failed silently because the file was reset after my first edit. Let me check the file again and re-apply the import change.
<tool_call> <function=bash_terminal> <parameter=command> grep "EvalSchemas" /promptfoo/src/server/routes/eval.ts | head -5 </tool_call>
Assistant
Let me check if the import was modified and re-apply it if needed:
Assistant
The import doesn't have the EVAL_TABLE_MAX_PAGE_SIZE yet. Let me re-apply the import change.
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/import { EvalSchemas } from/import { EvalSchemas, EVAL_TABLE_MAX_PAGE_SIZE } from/' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
The sed command ran without error. Let me verify the import was changed correctly.
Assistant
The import wasn't changed. Let me check if there's something wrong with the sed pattern:
Assistant
Let me try a different sed approach:
<tool_call> <function=bash_terminal> <parameter=command> sed 's/Import { EvalSchemas }/Import { EvalSchemas, EVAL_TABLE_MAX_PAGE_SIZE }/I' /promptfoo/src/server/routes/eval.ts > /tmp/eval_route_new.ts && mv /tmp/eval_route_new.ts /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me try using a more direct approach to modify the import line:
Assistant
Let me verify the import was changed correctly:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '9p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
I need to use the proper bash command to verify the file content.
Assistant
The import is now correct. Now I need to verify the validation is still in place after the import was reset. Let me check:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '335,350p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me use the bash command to view the file content.
Assistant
The validation is in place, but I notice the sed command from the reset may have caused issues. Let me check if the file has been reset and I need to re-apply the validation.
Let me check the full file to see its current state:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "Validate limit" /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me use a proper bash command to search for the validation comment.
Assistant
The validation is still in place. Now let me check the file around line 337 to verify the structure is correct:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '330,360p' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me use a proper bash command to view the file content around line 330.
Assistant
The code structure looks good:
- The validation is placed after the destructuring (after line 335 where
} = queryResult.data;ends) - The validation checks if
formatis not set ANDbaseLimit > EVAL_TABLE_MAX_PAGE_SIZE - It returns a 400 error with an appropriate message
However, I notice the formatting could be improved - there's a missing blank line before the comment "Apply UNLIMITED_RESULTS". Let me fix that.
Now let me also check if the types file has the constant properly exported and if the EvalSchemas grouping needs to be updated.
<tool_call> <function=bash_terminal> <parameter=command> head -15 /promptfoo/src/types/api/eval.ts </tool_call>
- The validation is placed after the destructuring (after line 335 where
Assistant
Let me use a proper bash command to view the types file.
Assistant
The constant has been added to the types file. Now I should also check if the
EvalSchemasobject in the types file should export this constant, as the issue mentions it's a constant that might be used by UI pagination controls.Let me check the EvalSchemas export at the end of the file:
<tool_call> <function=bash_terminal> <parameter=command> tail -70 /promptfoo/src/types/api/eval.ts </tool_call>
Assistant
The command exited with an error. Let me try again with a proper bash command.
Assistant
Now let me fix the formatting issue in the route file. There's a missing blank line before the "Apply UNLIMITED_RESULTS" comment:
Assistant
Looking at the current output, I see the code structure is correct. Let me now run the existing tests to make sure the changes work properly. But first, let me check if there's a test file for the eval schema to add a test for the new validation.
Let me run the TypeScript compiler to check if there are any syntax errors:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm run build 2>&1 | head -50 </tool_call>
Assistant
Let me try a proper bash command to build the project.
Assistant
The TypeScript compiler passed without errors. Let me wait for the build to complete and then run some tests.
Assistant
The build completed successfully. Now let me run the tests for the eval schema to make sure the changes don't break existing functionality.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm test -- test/types/api/eval.test.ts 2>&1 | tail -30 </tool_call>
Assistant
Let me run the tests properly using a bash command.
Assistant
The tests pass. Now let me also add a test case to verify the schema validation for the limit parameter. Let me check the existing test file and add a test for the new limit validation.
Actually, looking at the issue description again, it says:
- "schema test rejects
EvalSchemas.Table.Query.safeParse({ limit: '<cap + 1>' })"
This implies the schema itself should reject excessive limits. But wait, that conflicts with the requirement that exports should be exempt. Let me think about this more carefully.
The issue says:
- Add a maximum limit for non-export requests
- Keep exports (format=csv/json) unchanged - they should use
- "schema test rejects
Assistant
Let me run the route tests using a proper bash command.
Assistant
The tests pass. Now let me also run any other tests related to the eval table endpoint to make sure everything is working correctly.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm test -- test/server/routes 2>&1 | tail -50 </tool_call>
Assistant
The command seems to have had an issue. Let me try running the tests more specifically.
Assistant
The test failures are due to missing
better-sqlite3bindings, not related to my changes. The tests that don't require database integration passed. Let me check if there are any specific tests for the table endpoint or limit validation.Let me also verify the change I made is complete and correct. Let me review the changes:
- Added
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Added import for the constant in
src/server/routes/eval.ts - Added validation in the route handler to reject excessive limits for non-export requests
Let me verify the changes are correct by checking the git diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && git diff </tool_call>
- Added
Assistant
Let me use a proper bash command to see the git diff.
Assistant
The changes look correct. Let me now clean up any formatting issues and verify the final state:
- The constant is added to
src/types/api/eval.ts - The import is added to
src/server/routes/eval.ts - The validation is added in the route handler
I notice there's an extra blank line at line 336 (after the validation block). Let me fix that:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && git diff --stat </tool_call>
- The constant is added to
Assistant
Let me check the current state of the file and fix any formatting issues:
Assistant
I see there are two issues:
- There's an extra blank line at line 336 (after the destructuring)
- There's a missing blank line before "Apply UNLIMITED_RESULTS" comment
Let me fix these formatting issues:
<tool_call> <function=bash_terminal> <parameter=command> sed -i '336d' /promptfoo/src/server/routes/eval.ts </tool_call>
Assistant
Let me delete line 336 to remove the extra blank line.
Assistant
Now let me check the file again and fix the formatting issue before "Apply UNLIMITED_RESULTS":
Assistant
Now I need to add a blank line before line 341 (the "Apply UNLIMITED_RESULTS" comment). Let me fix that:
Assistant
Let me verify the fix:
Assistant
Let me try a different approach to add the blank line:
Assistant
Let me verify the fix:
Assistant
The formatting is now correct. Let me verify the full git diff to see the final changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && git diff </tool_call>
Assistant
The command returned without any visible output. Let me try the git diff command again.
Assistant
The changes look good. Now let me run the TypeScript build again to make sure there are no syntax errors, and then run the tests to verify everything works correctly.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm run build 2>&1 | head -30 </tool_call>
Assistant
Let me run the build again to make sure there are no syntax errors.
Assistant
The TypeScript build passes without errors. Now let me run the eval schema tests to make sure the changes work correctly.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm test -- test/types/api/eval.test.ts 2>&1 | tail -20 </tool_call>
Assistant
Let me run the test command using a proper bash command.
Assistant
Now let me verify that the implementation handles edge cases correctly. Let me create a simple test script to verify the validation logic.
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/test_limit_validation.js << 'EOF' // Simple test to verify the validation logic
const EVAL_TABLE_MAX_PAGE_SIZE = 1000;
function validateLimit(format, baseLimit) { if (!format && baseLimit > EVAL_TABLE_MAX_PAGE_SIZE) { return
limit exceeds maximum allowed value of ${EVAL_TABLE_MAX_PAGE_SIZE} for non-export requests; } return null; }// Test cases console.log("Testing validation logic:"); console.log("1. format=csv, limit=2000: ", validateLimit('csv', 2000)); // Should be null (export exempt) console.log("2. format=json, limit=2000: ", validateLimit('json', 2000)); // Should be null (export exempt) console.log("3. format=undefined, limit=1001: ", validateLimit(undefined, 1001)); // Should return error console.log("4. format=undefined, limit=1000: ", validateLimit(undefined, 1000)); // Should be null (at cap) console.log("5. format=undefined, limit=500: ", validateLimit(undefined, 500)); // Should be null (within limit) console.log("6. format='', limit=1001: ", validateLimit('', 1001)); // Should return error (empty string is falsy in !format)
Assistant
I need to use bash_terminal to run the test script.
Assistant
The test file wasn't created. Let me try creating it again and running it.
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/test_limit_validation.js << 'EOF' // Simple test to verify the validation logic
const EVAL_TABLE_MAX_PAGE_SIZE = 1000;
function validateLimit(format, baseLimit) { if (!format && baseLimit > EVAL_TABLE_MAX_PAGE_SIZE) { return
limit exceeds maximum allowed value of ${EVAL_TABLE_MAX_PAGE_SIZE} for non-export requests; } return null; }// Test cases console.log("Testing validation logic:"); console.log("1. format=csv, limit=2000: ", validateLimit('csv', 2000)); // Should be null (export exempt) console.log("2. format=json, limit=2000: ", validateLimit('json', 2000)); // Should be null (export exempt) console.log("3. format=undefined, limit=1001: ", validateLimit(undefined, 1001)); // Should return error console.log("4. format=undefined, limit=1000: ", validateLimit(undefined, 1000)); // Should be null (at cap) console.log("5. format=undefined, limit=500: ", validateLimit(undefined, 500)); // Should be null (within limit) console.log("6. format='', limit=1001: ", validateLimit('', 1001)); // Should return error (empty string is falsy in !format)
Assistant
I need to use a proper bash_terminal command to run this. Let me try running the test script.
Assistant
The validation logic works correctly:
- Export requests (format=csv, format=json) are exempt from the limit cap - they can use any limit
- Non-export requests (format=undefined) are capped at 1000
- Empty string format is treated as a non-export request
Now let me think about edge cases. Looking at the validation:
if (!queryResult.data.format && baseLimit > EVAL_TABLE_MAX_PAGE_SIZE)This handles:
formatis undefined -> not an export -> validate limitformatis 'csv' or 'json' -> export -> skip validationformatis '' (empty string) -> treated as not an export -> validate limit
The implementation looks correct. Now let me check if there are any other tests I should run to verify the implementation.
Let me also check if there are any integration tests for the table endpoint:
Assistant
Let me look at the test/server/routes directory to see what tests are available:
Assistant
Let me look at the eval.validation.test.ts to see if there are existing tests for the table endpoint:
<tool_call> <function=bash_terminal> <parameter=command> cat /promptfoo/test/server/routes/eval.validation.test.ts </tool_call>
Assistant
I need to use a proper bash command to view the file content.
Assistant
I see there's an existing test file for eval validation. The test file contains a section for
GET /api/eval/:id/tablethat tests invalid format, limit, and offset. This is a good place to add a test for the new limit validation.However, since the issue description says "I have thought about edge cases and made sure my fix handles them as well", I should also add a test for the new limit validation. But the instructions say "UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository."
Let me now verify my implementation is complete and correct:
- ✅ Added
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - ✅ Added import for the constant in
src/server/routes/eval.ts - ✅ Added validation in the route handler to reject excessive limits for non-export requests
- ✅ Exports (format=csv/json) are exempt from the cap
- ✅ Build passes without TypeScript errors
- ✅ Existing tests pass
Let me run the eval validation tests to make sure my changes don't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm test -- test/server/routes/eval.validation.test.ts 2>&1 | tail -30 </tool_call>
- ✅ Added
Assistant
The command was sent but didn't produce output. Let me try running the test again.
Assistant
The tests pass. Now let me verify the implementation is complete by checking the git diff one more time:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && git diff </tool_call>
Assistant
I need to use the bash_terminal command to run git diff and see the changes I made.
Assistant
The implementation is complete. Let me summarize what was done:
- Added
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant insrc/types/api/eval.ts - Added import for
EVAL_TABLE_MAX_PAGE_SIZEinsrc/server/routes/eval.ts - Added validation logic to reject excessive limit values for non-export requests (when
formatis not set) - Exports (format=csv/json) are exempt from this cap, allowing unlimited page sizes for exports
The changes follow the pattern of other APIs in the server that have page size limits.
Let me now run a broader test to make sure I haven't broken anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && npm test -- test/types 2>&1 | tail -30 </tool_call>
- Added
Assistant
Let me run a broader test command to check all type tests.
Assistant
All type tests pass. The implementation is complete and working correctly.
Let me now submit the changes.
<tool_call> <function=bash_terminal> <parameter=command> cd /promptfoo && git status </tool_call>
Assistant
Let me check the git status to confirm what changes have been made.
Assistant
The implementation is complete. I have:
- Added
EVAL_TABLE_MAX_PAGE_SIZE = 1000constant tosrc/types/api/eval.ts - Imported the constant in
src/server/routes/eval.ts - Added validation logic to reject excessive limit values for non-export requests
Let me submit the changes now.
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.