Skip to content

bug(core): ReadFile tool rejects empty string for optional 'pages' parameter #3558

@zhangxy-zju

Description

@zhangxy-zju

Summary

After #3160, any ReadFile call that includes pages: "" (empty string) is rejected with:

Invalid pages parameter: ''. Use formats like '5' or '1-10'.

Some tool-calling models (including Qwen/DeepSeek variants) default optional string parameters to "" rather than omitting the field. Every read_file call from those models now fails at validation, regardless of file type.

Reproduction

Any of:

  • From a model that fills optional strings with "", run read_file on any file — it fails with the error above.
  • parsePDFPageRange('') returns null directly.
  • Unit test: call tool.build({ file_path: '/tmp/a.txt', pages: '' }) → throws Invalid pages parameter.

Root cause

packages/core/src/tools/read-file.ts:267 gates validation on params.pages !== undefined. Empty string is not undefined, so it falls into parsePDFPageRange(''), which returns null (utils/pdf.ts:97-100), producing the error.

Introduced by #3160 (feat(core): PDF text extraction fallback and Jupyter notebook parsing, merged 2026-04-20).

Expected

Empty string should be treated the same as an omitted parameter.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions