crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] DOCXSearchTool crashes with ValidationError when initialized with a fixed docx

Open Rohitkanithi opened this issue 2 months ago • 3 comments

Description

When DOCXSearchTool is initialized with a fixed document path: tool = DOCXSearchTool(docx="document.docx") the tool sets self.args_schema = FixedDOCXSearchToolSchema.

However, in FixedDOCXSearchToolSchema, the docx field is mistakenly marked as required (Field(...)). When an agent executes the tool with only {"search_query": "..."}, Pydantic raises a ValidationError: ValidationError: 1 validation error for FixedDOCXSearchToolSchema: docx: Field required

Unlike all sibling tools (CSVSearchTool, PDFSearchTool, JSONSearchTool, DirectorySearchTool), DOCXSearchTool accidentally inverted its schema inheritance, making the fixed mode require docx and breaking agent tool calls.

Steps to Reproduce

  1. Initialize DOCXSearchTool with a fixed document: tool = DOCXSearchTool(docx="sample.docx")

  2. Validate the input that an agent sends during tool execution: tool.args_schema.model_validate({"search_query": "quarterly revenue"})

  3. Pydantic raises: ValidationError: 1 validation error for FixedDOCXSearchToolSchema docx: Field required [type=missing, input_value={'search_query': '...'}, input_type=dict]

Expected behavior

When DOCXSearchTool is initialized with a fixed docx file, FixedDOCXSearchToolSchema should only require search_query. DOCXSearchToolSchema should inherit from FixedDOCXSearchToolSchema and add docx: str = Field(...) for runtime/dynamic mode.

Screenshots/Code snippets

Current buggy definition in docx_search_tool.py:

class FixedDOCXSearchToolSchema(BaseModel): docx: str | None = Field( ..., description="File path or URL of a DOCX file to be searched" # BUG: required in fixed mode! ) search_query: str = Field( ..., description="Mandatory search query you want to use to search the DOCX's content", )

class DOCXSearchToolSchema(FixedDOCXSearchToolSchema): search_query: str = Field( ..., description="Mandatory search query you want to use to search the DOCX's content", )

Operating System

macOS Sonoma

Python Version

3.12

crewAI Version

1.15.20

crewAI Tools Version

1.15.20

Virtual Environment

Venv

Evidence

Sibling tools follow the standard RAG schema pattern:

  • CSVSearchTool: FixedCSVSearchToolSchema requires only search_query; CSVSearchToolSchema adds csv.
  • PDFSearchTool: FixedPDFSearchToolSchema requires only query; PDFSearchToolSchema adds pdf.
  • JSONSearchTool: FixedJSONSearchToolSchema requires only search_query; JSONSearchToolSchema adds json_path.
  • DirectorySearchTool: FixedDirectorySearchToolSchema requires only search_query; DirectorySearchToolSchema adds directory.

DOCXSearchTool is the only tool where the fixed schema requires the file path.

Possible Solution

class FixedDOCXSearchToolSchema(BaseModel): """Input for DOCXSearchTool."""

search_query: str = Field(
    ...,
    description="Mandatory search query you want to use to search the DOCX's content",
)

class DOCXSearchToolSchema(FixedDOCXSearchToolSchema): """Input for DOCXSearchTool."""

docx: str = Field(..., description="File path or URL of a DOCX file to be searched")

Additional context

I am actively working on the fix and have regression tests ready.

Rohitkanithi avatar Sep 09 '26 16:09 Rohitkanithi

Hi maintainers,

I would love to work on this issue!

I have already developed the patch aligning DOCXSearchTool with the standard RAG schema pattern (matching CSVSearchTool, PDFSearchTool, and JSONSearchTool), along with dedicated unit tests in test_docx_search_tool.py. All local checks (pytest, mypy, and ruff) are passing cleanly.

Could you please assign this issue to me, If the proposed solution looks good to you, I can open the PR right away.

Thanks!

Rohitkanithi avatar Sep 09 '26 16:09 Rohitkanithi

@Rohitkanithi, sure assigning it to you.

Vidit-Ostwal avatar Sep 09 '26 16:09 Vidit-Ostwal

OSS-147

linear[bot] avatar Sep 10 '26 05:09 linear[bot]