Skip to content

Filesystem tools fail validation on weaker/custom models due to path/file_path parameter mismatch #658

Description

Describe the bug

When using weaker or custom LLMs (e.g., smaller open-source models or custom endpoints) in deepagents and consumers like openwiki, the agent immediately crashes with a schema validation error on the first read_file call:

Root Cause

There are two contributing factors to this issue:

  1. Schema Inconsistency: The ls tool defines its directory argument as path, while read_file, write_file, and edit_file define their target file argument as file_path. Models often generalize tool naming conventions and default to using path across all filesystem tools.
  2. Confusing Prompt Examples: Both READ_FILE_TOOL_DESCRIPTION (in fs.ts) and the skills system prompt (in skills.ts) show documentation examples instructing the model to use path, e.g. read_file(path, limit=100). Less capable models strictly copy this behavior and fail the actual Zod schema validation because it expects file_path.

Proposed Solution

We should implement both a prompt correction and a defensive input normalization layer so that filesystem tools work reliably across all model tiers.

  1. Prompt Corrections: Align the documentation examples in fs.ts and skills.ts to use file_path (as initiated in PR fix(deepagents): use file_path in read_file prompt examples #644).
  2. Schema Input Normalization: Add a z.preprocess helper to read_file, write_file, and edit_file schemas to dynamically map path to file_path if the model passes path.

Implementation Example:

function normalizeFilePathInput(input: unknown): unknown {
  if (
    typeof input === "object" &&
    input !== null &&
    "path" in input &&
    !("file_path" in input)
  ) {
    const { path, ...rest } = input as Record<string, unknown>;
    return { ...rest, file_path: path };
  }
  return input;
}

// Wrap schemas
schema: z.preprocess(normalizeFilePathInput, z.object({
  file_path: z.string().describe("Absolute path to the file to read"),
  // ...
}))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions